Skip to content

Commit

Permalink
添加Logback日志框架
Browse files Browse the repository at this point in the history
  • Loading branch information
icuxika committed Mar 23, 2024
1 parent 158517e commit fbc3314
Show file tree
Hide file tree
Showing 14 changed files with 610 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ out/
target/
*.iml
/.gradle/

/logs
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,8 @@ mvn -Pwin gluonfx:build -D"https.proxyHost"=127.0.0.1 -D"https.proxyPort"=7890
mvn -Pmac gluonfx:build -D"https.proxyHost"=127.0.0.1 -D"https.proxyPort"=7890
```

## 日志
添加了支持GraalVM的Logback作为日志框架,在你自己的项目,如果是第一次添加以及后续修改了Logback配置文件的时候,在执行GraalVM构建之前,先用`mvn -Pwin gluonfx:runagent``.\gradlew.bat nativeRunAgent`来为`native-image`生成一些必要的文件,它会自动保存到`src/main/resources/META-INF/native-image`,然后在执行GraalVM构建,否则生成的程序执行时不会生成日志文件,正常情况下,会在程序执行目录创建`logs`目录及日志文件

## 补充
有时候`mvn gluonfx:build`或者`.\gradlew.bat jpackageImage`发生了错误后,执行`.\gradlew.bat clean`提示文件被占用,这时候可以打开`任务管理器-性能-资源监视器-CPU`,在`关联的句柄`处输入`gluon``jpackage`等关键词来检索出卡住的相关进程并干掉他
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ javafx {

dependencies {
implementation("io.github.palexdev:materialfx:11.16.1")
implementation("org.slf4j:slf4j-api:2.0.12")
implementation("ch.qos.logback:logback-classic:1.5.3")
}

jlink {
Expand Down
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@
<artifactId>materialfx</artifactId>
<version>11.16.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.12</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.3</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/icuxika/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Locale;

public class MainApp extends Application {

private static final Logger LOGGER = LoggerFactory.getLogger(MainApp.class);

@Override
public void start(Stage primaryStage) throws Exception {
AppResource.setLanguage(Locale.SIMPLIFIED_CHINESE);
Expand Down Expand Up @@ -47,6 +51,12 @@ public void start(Stage primaryStage) throws Exception {
primaryStage.titleProperty().bind(AppResource.getLanguageBinding("title"));
primaryStage.setScene(new Scene(vBox, 600, 400));
primaryStage.show();

LOGGER.trace("[trace]日志控制台输出");
LOGGER.debug("[debug]日志控制台输出");
LOGGER.info("[info]日志记录到logs/application.log中");
LOGGER.warn("[warn]日志记录到logs/application.log中");
LOGGER.error("[error]日志记录到logs/application.log中");
}

public static void main(String[] args) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
requires javafx.web;

requires MaterialFX;
requires org.slf4j;

exports com.icuxika;
}
11 changes: 11 additions & 0 deletions src/main/resources/META-INF/native-image/filter-file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ "rules": [
{"excludeClasses" : "com.sun.glass.ui.mac.*"},
{"excludeClasses" : "com.sun.glass.ui.gtk.*"},
{"excludeClasses" : "com.sun.glass.ui.win.*"},
{"excludeClasses" : "com.sun.prism.es2.*"},
{"excludeClasses" : "com.sun.prism.d3d.*"},
{"excludeClasses" : "com.sun.scenario.effect.impl.es2.*"},
{"excludeClasses" : "com.sun.scenario.effect.impl.hw.d3d.*"},
{"excludeClasses" : "com.gluonhq.attach.**"}
]
}
61 changes: 61 additions & 0 deletions src/main/resources/META-INF/native-image/jni-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[
{
"name":"[Lcom.sun.glass.ui.Screen;"
},
{
"name":"com.sun.glass.ui.Cursor",
"methods":[{"name":"getNativeCursor","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }]
},
{
"name":"com.sun.glass.ui.Screen",
"methods":[{"name":"<init>","parameterTypes":["long","int","int","int","int","int","int","int","int","int","int","int","int","int","int","int","float","float","float","float"] }]
},
{
"name":"com.sun.glass.ui.Size",
"methods":[{"name":"<init>","parameterTypes":["int","int"] }]
},
{
"name":"com.sun.javafx.font.directwrite.DWRITE_GLYPH_METRICS",
"fields":[{"name":"advanceHeight"}, {"name":"advanceWidth"}, {"name":"bottomSideBearing"}, {"name":"leftSideBearing"}, {"name":"rightSideBearing"}, {"name":"topSideBearing"}, {"name":"verticalOriginY"}],
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.sun.javafx.font.directwrite.DWRITE_GLYPH_RUN",
"fields":[{"name":"advanceOffset"}, {"name":"ascenderOffset"}, {"name":"bidiLevel"}, {"name":"fontEmSize"}, {"name":"fontFace"}, {"name":"glyphAdvances"}, {"name":"glyphIndices"}, {"name":"isSideways"}],
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.sun.javafx.font.directwrite.DWRITE_MATRIX",
"fields":[{"name":"dx"}, {"name":"dy"}, {"name":"m11"}, {"name":"m12"}, {"name":"m21"}, {"name":"m22"}],
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.sun.javafx.font.directwrite.RECT",
"fields":[{"name":"bottom"}, {"name":"left"}, {"name":"right"}, {"name":"top"}],
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.sun.prism.impl.PrismSettings",
"fields":[{"name":"disableD3D9Ex"}, {"name":"forceGPU"}, {"name":"isVsyncEnabled"}, {"name":"verbose"}]
},
{
"name":"java.lang.Class",
"methods":[{"name":"forName","parameterTypes":["java.lang.String","boolean","java.lang.ClassLoader"] }]
},
{
"name":"java.lang.Runnable",
"methods":[{"name":"run","parameterTypes":[] }]
},
{
"name":"java.lang.String",
"methods":[{"name":"toLowerCase","parameterTypes":["java.util.Locale"] }]
},
{
"name":"java.util.ArrayList",
"methods":[{"name":"<init>","parameterTypes":["int"] }, {"name":"add","parameterTypes":["java.lang.Object"] }]
},
{
"name":"java.util.HashMap",
"methods":[{"name":"containsKey","parameterTypes":["java.lang.Object"] }, {"name":"put","parameterTypes":["java.lang.Object","java.lang.Object"] }]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"type":"agent-extracted",
"classes":[
]
}
]

2 changes: 2 additions & 0 deletions src/main/resources/META-INF/native-image/proxy-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[
]
Loading

0 comments on commit fbc3314

Please sign in to comment.