Sfoglia il codice sorgente

解决日志无法输出问题

johnclot69 3 mesi fa
parent
commit
5dc59a8179

+ 1 - 1
incubator-common/build.gradle

@@ -14,7 +14,7 @@ dependencies {
     api 'org.slf4j:slf4j-api:2.0.16'
     //声明slf4j转SLF4J的桥接包
 //    api 'org.apache.logging.log4j:log4j-slf4j-impl:2.19.0'
-    testImplementation 'org.apache.logging.log4j:log4j-slf4j2-impl:2.24.1'
+    api 'org.apache.logging.log4j:log4j-slf4j2-impl:2.24.1'
     //使用log4j2作为实际的日志实现
     api 'org.apache.logging.log4j:log4j-api:2.24.1'
     api 'org.apache.logging.log4j:log4j-core:2.24.1'

+ 18 - 0
incubator-game/build.gradle

@@ -11,9 +11,22 @@ repositories {
     mavenCentral()
 }
 
+sourceSets {
+    main {
+        resources {
+            srcDirs += 'conf'
+        }
+    }
+}
+
 application {
     // 使用新的方法设置主类,适应 Gradle 7.0 及以上版本
     mainClass.set('com.incubator.game.GameServerStart')
+
+    // 添加 JVM 参数,指定 conf 目录下的配置文件路径
+    applicationDefaultJvmArgs = [
+            "-Dlog4j.configurationFile=conf/log4j2.xml"
+    ]
 }
 
 // 禁用默认的 JAR 任务,因为我们使用 Shadow JAR
@@ -38,6 +51,11 @@ tasks.shadowJar {
         )
     }
 
+    // 将 conf 目录包含到最终的 JAR 文件中
+    from('conf') {
+        into('conf') // 指定 JAR 内的路径
+    }
+
     // 可选:排除不必要的依赖
     exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA'
 }

+ 2 - 2
incubator-game/conf/log4j2.xml

@@ -2,8 +2,8 @@
 <configuration status="WARN" monitorInterval="1800">
 	<properties>
 		<property name="LOG_HOME">logs</property>
-		<property name="LOG_LEVEL_FILE">INFO</property>
-		<property name="LOG_LEVEL_CONSOLE">INFO</property>
+		<property name="LOG_LEVEL_FILE">DEBUG</property>
+		<property name="LOG_LEVEL_CONSOLE">DEBUG</property>
 		<property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n</property>
 	</properties>