下面是在log4j2.xml中配置的JSONLayout
<JSONLayout complete="true" charset="UTF-8" compact="true">
<KeyValuePair key="application-name" value="sample-app"></KeyValuePair>
</JSONLayout>
POM.xml
org.apache.logging.log4j:log4j-core:jar:2.7:compile
org.apache.logging.log4j:log4j-api:jar:2.7:compile
org.apache.logging.log4j:log4j-jul:jar:2.7:compile
com.fasterxml.jackson.core:jackson-databind:jar:2.9.9:compile
我看到消息以JSON格式打印,但是不知道键值对。
2019-06-01 21:11:23,305 localhost-startStop-1 ERROR layout JSONLayout has no parameter that matches element KeyValuePair
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
知道为什么不能识别键值对吗?
答案 0 :(得分:0)
log4j2 2.7版没有将此KeyValuePair
功能作为JSONLayout
的嵌套元素。使用2.11.2
版或log4j依赖项来解决它-
org.apache.logging.log4j:log4j-core:jar:2.11.2:compile
org.apache.logging.log4j:log4j-api:jar:2.11.2:compile
org.apache.logging.log4j:log4j-jul:jar:2.11.2:compile
com.fasterxml.jackson.core:jackson-databind:jar:2.9.9:compile