[英]Why is Log4j2 JsonLayout + KeyValuePair printing empty logEvent messages
TL;DR If I'm using JsonLayout with a nested KeyValuePair in my log4j2.xml config the resulting log messages are empty. TL; DR如果我在Log4j2.xml配置中使用带有嵌套KeyValuePair的JsonLayout,则生成的日志消息为空。 Any ideas why? 有什么想法吗?
Long Story 很长的故事
I'm using Tomcat 8.5.43 with the following logging related JARs: 我将Tomcat 8.5.43与以下与日志记录相关的JAR一起使用:
and the log4j2.xml config: 和log4j2.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="consoleappender" target="SYSTEM_OUT">
<JsonLayout compact="true" eventEol="true" stacktraceAsString="true" locationInfo="true">
<KeyValuePair key="foo" value="bar"/>
</JsonLayout>
</Console>
<Loggers>
<Root level="info">
<AppenderRef ref="consoleappender" />
</Root>
</Loggers>
</Configuration>
In the setenv.sh I set the classpath to: 在setenv.sh中,我将类路径设置为:
CLASSPATH="$JAVA_HOME/lib/tools.jar\
:$CATALINA_HOME/lib/log4j-api.jar\
:$CATALINA_HOME/lib/log4j-core.jar\
:$CATALINA_HOME/lib/log4j-jul.jar\
:$CATALINA_HOME/lib/jackson-annotations.jar\
:$CATALINA_HOME/lib/jackson-core.jar\
:$CATALINA_HOME/lib/jackson-databind.jar"
And run Tomcat with the additional JVM args: 并使用其他JVM参数运行Tomcat:
-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
-Dlog4j.configurationFile=file:log4j2.xml"
So every Tomcat, JULI, Apache commons and Slf4j logging should be redirected to Log4J2 in the end. 因此,每个Tomcat,JULI,Apache Commons和Slf4j日志都应最终重定向到Log4J2。
Unfortunately all I see is this: {"logEvent":"","foo":"bar"}
不幸的是,我所看到的是: {"logEvent":"","foo":"bar"}
Instead of something like this: {"thread":"main","level":"INFO","loggerName":"org.apache.catalina.startup.VersionLoggerListener","message":"Server version: Apache Tomcat/8.5.43","endOfBatch":false,"loggerFqcn":"org.apache.logging.log4j.jul.ApiLogger","threadId":1,"source":{"class":"org.apache.juli.logging.impl.Jdk14Logger","method":"log","file":"Jdk14Logger.java","line":87},"threadPriority":5,"instant":{"epochSecond":1562919500,"nanoOfSecond":701000000}}
而不是这样的: {"thread":"main","level":"INFO","loggerName":"org.apache.catalina.startup.VersionLoggerListener","message":"Server version: Apache Tomcat/8.5.43","endOfBatch":false,"loggerFqcn":"org.apache.logging.log4j.jul.ApiLogger","threadId":1,"source":{"class":"org.apache.juli.logging.impl.Jdk14Logger","method":"log","file":"Jdk14Logger.java","line":87},"threadPriority":5,"instant":{"epochSecond":1562919500,"nanoOfSecond":701000000}}
If I remove the KeyValuePair
everything works fine as expected. 如果我删除KeyValuePair
一切都会按预期工作。
What's the issue here? 这里有什么问题?
I'm experiencing the same problem. 我遇到了同样的问题。 It's somehow related to log4j-2.12.0, in 2.11.2 it is OK. 它与log4j-2.12.0有某种关系,在2.11.2中可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.