Reputation: 2081
I have below simple config for log4j2 which just log the message to console stdout and a file:
<?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>
It working fine, but if I change to JSON config, if doesn't work, if anybody have any clue?
{ "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" }
}
}
}
}
Upvotes: 4
Views: 1223
Reputation: 3111
The log4j2 JSON (or any JSON for that matter) doesn't allow two "AppenderRef" entries to exist, so you should use a config more like the following
{ "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" }
]
}
}
}
}
You can also use 'appender-ref' instead of AppenderRef
Upvotes: 5
Reputation: 36754
You may have found a bug. Could you file a Jira ticket in the log4j2 issue tracker?
Upvotes: 0