Skip to content

Commit fbc3314

Browse files
committed
添加Logback日志框架
1 parent 158517e commit fbc3314

14 files changed

+610
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ out/
44
target/
55
*.iml
66
/.gradle/
7-
7+
/logs

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,8 @@ mvn -Pwin gluonfx:build -D"https.proxyHost"=127.0.0.1 -D"https.proxyPort"=7890
129129
mvn -Pmac gluonfx:build -D"https.proxyHost"=127.0.0.1 -D"https.proxyPort"=7890
130130
```
131131

132+
## 日志
133+
添加了支持GraalVM的Logback作为日志框架,在你自己的项目,如果是第一次添加以及后续修改了Logback配置文件的时候,在执行GraalVM构建之前,先用`mvn -Pwin gluonfx:runagent``.\gradlew.bat nativeRunAgent`来为`native-image`生成一些必要的文件,它会自动保存到`src/main/resources/META-INF/native-image`,然后在执行GraalVM构建,否则生成的程序执行时不会生成日志文件,正常情况下,会在程序执行目录创建`logs`目录及日志文件
134+
132135
## 补充
133136
有时候`mvn gluonfx:build`或者`.\gradlew.bat jpackageImage`发生了错误后,执行`.\gradlew.bat clean`提示文件被占用,这时候可以打开`任务管理器-性能-资源监视器-CPU`,在`关联的句柄`处输入`gluon``jpackage`等关键词来检索出卡住的相关进程并干掉他

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ javafx {
3535

3636
dependencies {
3737
implementation("io.github.palexdev:materialfx:11.16.1")
38+
implementation("org.slf4j:slf4j-api:2.0.12")
39+
implementation("ch.qos.logback:logback-classic:1.5.3")
3840
}
3941

4042
jlink {

pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@
5555
<artifactId>materialfx</artifactId>
5656
<version>11.16.1</version>
5757
</dependency>
58+
<dependency>
59+
<groupId>org.slf4j</groupId>
60+
<artifactId>slf4j-api</artifactId>
61+
<version>2.0.12</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>ch.qos.logback</groupId>
65+
<artifactId>logback-classic</artifactId>
66+
<version>1.5.3</version>
67+
</dependency>
5868
</dependencies>
5969
<build>
6070
<plugins>

src/main/java/com/icuxika/MainApp.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
import javafx.scene.layout.VBox;
1414
import javafx.scene.paint.Color;
1515
import javafx.stage.Stage;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
1618

1719
import java.util.Locale;
1820

1921
public class MainApp extends Application {
2022

23+
private static final Logger LOGGER = LoggerFactory.getLogger(MainApp.class);
24+
2125
@Override
2226
public void start(Stage primaryStage) throws Exception {
2327
AppResource.setLanguage(Locale.SIMPLIFIED_CHINESE);
@@ -47,6 +51,12 @@ public void start(Stage primaryStage) throws Exception {
4751
primaryStage.titleProperty().bind(AppResource.getLanguageBinding("title"));
4852
primaryStage.setScene(new Scene(vBox, 600, 400));
4953
primaryStage.show();
54+
55+
LOGGER.trace("[trace]日志控制台输出");
56+
LOGGER.debug("[debug]日志控制台输出");
57+
LOGGER.info("[info]日志记录到logs/application.log中");
58+
LOGGER.warn("[warn]日志记录到logs/application.log中");
59+
LOGGER.error("[error]日志记录到logs/application.log中");
5060
}
5161

5262
public static void main(String[] args) {

src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
requires javafx.web;
99

1010
requires MaterialFX;
11+
requires org.slf4j;
1112

1213
exports com.icuxika;
1314
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{ "rules": [
2+
{"excludeClasses" : "com.sun.glass.ui.mac.*"},
3+
{"excludeClasses" : "com.sun.glass.ui.gtk.*"},
4+
{"excludeClasses" : "com.sun.glass.ui.win.*"},
5+
{"excludeClasses" : "com.sun.prism.es2.*"},
6+
{"excludeClasses" : "com.sun.prism.d3d.*"},
7+
{"excludeClasses" : "com.sun.scenario.effect.impl.es2.*"},
8+
{"excludeClasses" : "com.sun.scenario.effect.impl.hw.d3d.*"},
9+
{"excludeClasses" : "com.gluonhq.attach.**"}
10+
]
11+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
[
2+
{
3+
"name":"[Lcom.sun.glass.ui.Screen;"
4+
},
5+
{
6+
"name":"com.sun.glass.ui.Cursor",
7+
"methods":[{"name":"getNativeCursor","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }]
8+
},
9+
{
10+
"name":"com.sun.glass.ui.Screen",
11+
"methods":[{"name":"<init>","parameterTypes":["long","int","int","int","int","int","int","int","int","int","int","int","int","int","int","int","float","float","float","float"] }]
12+
},
13+
{
14+
"name":"com.sun.glass.ui.Size",
15+
"methods":[{"name":"<init>","parameterTypes":["int","int"] }]
16+
},
17+
{
18+
"name":"com.sun.javafx.font.directwrite.DWRITE_GLYPH_METRICS",
19+
"fields":[{"name":"advanceHeight"}, {"name":"advanceWidth"}, {"name":"bottomSideBearing"}, {"name":"leftSideBearing"}, {"name":"rightSideBearing"}, {"name":"topSideBearing"}, {"name":"verticalOriginY"}],
20+
"methods":[{"name":"<init>","parameterTypes":[] }]
21+
},
22+
{
23+
"name":"com.sun.javafx.font.directwrite.DWRITE_GLYPH_RUN",
24+
"fields":[{"name":"advanceOffset"}, {"name":"ascenderOffset"}, {"name":"bidiLevel"}, {"name":"fontEmSize"}, {"name":"fontFace"}, {"name":"glyphAdvances"}, {"name":"glyphIndices"}, {"name":"isSideways"}],
25+
"methods":[{"name":"<init>","parameterTypes":[] }]
26+
},
27+
{
28+
"name":"com.sun.javafx.font.directwrite.DWRITE_MATRIX",
29+
"fields":[{"name":"dx"}, {"name":"dy"}, {"name":"m11"}, {"name":"m12"}, {"name":"m21"}, {"name":"m22"}],
30+
"methods":[{"name":"<init>","parameterTypes":[] }]
31+
},
32+
{
33+
"name":"com.sun.javafx.font.directwrite.RECT",
34+
"fields":[{"name":"bottom"}, {"name":"left"}, {"name":"right"}, {"name":"top"}],
35+
"methods":[{"name":"<init>","parameterTypes":[] }]
36+
},
37+
{
38+
"name":"com.sun.prism.impl.PrismSettings",
39+
"fields":[{"name":"disableD3D9Ex"}, {"name":"forceGPU"}, {"name":"isVsyncEnabled"}, {"name":"verbose"}]
40+
},
41+
{
42+
"name":"java.lang.Class",
43+
"methods":[{"name":"forName","parameterTypes":["java.lang.String","boolean","java.lang.ClassLoader"] }]
44+
},
45+
{
46+
"name":"java.lang.Runnable",
47+
"methods":[{"name":"run","parameterTypes":[] }]
48+
},
49+
{
50+
"name":"java.lang.String",
51+
"methods":[{"name":"toLowerCase","parameterTypes":["java.util.Locale"] }]
52+
},
53+
{
54+
"name":"java.util.ArrayList",
55+
"methods":[{"name":"<init>","parameterTypes":["int"] }, {"name":"add","parameterTypes":["java.lang.Object"] }]
56+
},
57+
{
58+
"name":"java.util.HashMap",
59+
"methods":[{"name":"containsKey","parameterTypes":["java.lang.Object"] }, {"name":"put","parameterTypes":["java.lang.Object","java.lang.Object"] }]
60+
}
61+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"type":"agent-extracted",
4+
"classes":[
5+
]
6+
}
7+
]
8+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[
2+
]

0 commit comments

Comments
 (0)