log4j2错误:正在运行通过Gradle生成的jar-log4j:WARN找不到记录器的追加器
注意:已编辑的文件名/包名已更改log4j2错误:正在运行通过Gradle生成的jar-log4j:WARN找不到记录器的追加器,gradle,jar,log4j2,Gradle,Jar,Log4j2,注意:已编辑的文件名/包名已更改 $>> java -jar build\lib\somePackageName.jar log4j:WARN No appenders could be found for logger (xxx.xxx.xxxx.xxxxx). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/f
$>> java -jar build\lib\somePackageName.jar
log4j:WARN No appenders could be found for logger (xxx.xxx.xxxx.xxxxx).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
已验证的jar具有log4j2.xml:
$>> jar tf build\libs\somePackageName.jar | ack -i "log4j2"
META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat
META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat
log4j2.xml
用于构建具有依赖项的Jar的Gradle任务:
sourceSets {
main {
resources {
srcDirs = ['src/resources']
}
}
}
task someFatJar(type: Jar) {
manifest {
attributes (
'Implementation-Title': 'xxxxx-xxxxxxxx',
'Implementation-Version': 0.x,
'Main-Class': 'xxx.xxxxx.xxxxx.xxxxxxxxxxxx'
)
}
baseName = 'someJarName'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
项目树:
src\main\java\someJavaFile.java
src\resources\log4j2.xml
以防万一,我尝试将资源目录移动到main下
救命啊 类似于log4j:WARN的错误消息是由旧的log4j 1.2实现生成的。您需要删除该依赖项,并用log4j-1.2-api适配器替换它。这样,您就可以使用Log4j2作为编码到log4j1.2api的应用程序的日志后端 解决方案: 使用slf4j+log4j2依赖关系是问题所在!替换如下所示的依赖项不要使用slf4j-log4j-impl,请使用log4j2 log4j-slf4j-impl提供的:
dependencies {
compile 'org.slf4j:slf4j-api:1.7.25'
compile 'org.apache.logging.log4j:log4j-api:2.8.2'
compile 'org.apache.logging.log4j:log4j-core:2.8.2'
compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.8.2'
}