我有以下简单的log4j2配置,它只是将消息记录到console stdout和一个文件:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<RandomAccessFile name="FILE" fileName="app.log">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
</RandomAccessFile>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%m%n" />
</Console>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="FILE" />
<AppenderRef ref="STDOUT" />
</Root>
</Loggers>
</Configuration>
它工作正常,但如果我改为JSON配置,如果不起作用,如果有人有任何线索?
{ "configuration":
{
"appenders": {
"RandomAccessFile": { "name": "FILE", "fileName": "app.log",
"PatternLayout": { "pattern": "%d %p %c{1.} [%t] %m%n" }
},
"Console": { "name": "STDOUT",
"PatternLayout": { "pattern": "%m%n" }
}
},
"loggers": {
"root": { "level": "trace",
"AppenderRef": { "ref": "STDOUT" },
"AppenderRef": { "ref": "FILE" }
}
}
}
}
答案 0 :(得分:5)
log4j2 JSON(或任何JSON)并不允许两个&#34; AppenderRef&#34;条目存在,因此您应该使用更像以下
的配置{ "configuration":
{
"appenders": {
"RandomAccessFile": { "name": "FILE", "fileName": "app.log",
"PatternLayout": { "pattern": "%d %p %c{1.} [%t] %m%n" }
},
"Console": { "name": "STDOUT",
"PatternLayout": { "pattern": "%m%n" }
}
},
"loggers": {
"root": { "level": "trace",
"AppenderRef": [
{ "ref": "STDOUT" },
{ "ref": "FILE" }
]
}
}
}
}
你也可以使用&#39; appender-ref&#39;而不是AppenderRef
答案 1 :(得分:0)
您可能发现了一个错误。你能在log4j2问题跟踪器中提交一个Jira票吗?