You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "David W. Urry (Jira)" <ji...@apache.org> on 2019/10/17 19:23:00 UTC
[jira] [Created] (LOG4J2-2708) JSON Layout incorrect for files
David W. Urry created LOG4J2-2708:
-------------------------------------
Summary: JSON Layout incorrect for files
Key: LOG4J2-2708
URL: https://issues.apache.org/jira/browse/LOG4J2-2708
Project: Log4j 2
Issue Type: Bug
Components: Appenders
Affects Versions: 2.12.1, 2.11.2, 2.11.1, 2.11.0
Environment: Code sample to produce log message (in Scala)
{code:java}
val map = new LinkedHashMap[String, String]()
map.put("id", "3")
map.put("event", "Performance")
logger.info(map)
{code}
Scala 2.11
Log4J 2.11.0
Jackson 2.6.5
Run using Scala IDE (Eclipse Oxygen Build id: 4.7.0-vfinal-2017-09-29T14:34:02Z-Typesafe)
Configured using Log4J2.xml as follows:
{code:java}
...
<File name="Performance" fileName="logs/performance.log">
<JsonLayout complete="true" compact="false"> </JsonLayout>
<MapFilter onMatch="ACCEPT" onMismatch="DENY">
<KeyValuePair key="id" value="3"/>
</MapFilter>
</File>
...
{code}
Note that this breaks the map filter because no key can be found in the message which is interpreted as a string. However, more importantly, it breaks the usefulness of supporting JSON in Log4j because the JSON format is broken meaning the log file can not be read by a JSON parser.
Reporter: David W. Urry
Attachments: performance.log
Log4j quotes the JSON message when put in a file. Console output is correct. File output is incorrect. Note that the entire JSON object is quoted when sent to the file instead of being stored as a JSON object it is stored as a string.
File records this incorrect JSON message:
{code:java}
{
...log4j json...
"message" : "{id=3, event=Performance}",
....
}
{code}
Console correctly reports a JSON message this way:
{code:java}
{...
"message" : {
"id" : "3",
"event" : "Performance"
},
...}
{code}
Entire JSON Message from Console:
{code:java}
{
"thread" : "main",
"level" : "INFO",
"loggerName" : "###.###.###.$###",
"message" : {
"id" : "3",
"event" : "Performance"
},
"endOfBatch" : false,
"loggerFqcn" : "org.apache.logging.log4j.scala.Logger$",
"instant" : {
"epochSecond" : 1571338092,
"nanoOfSecond" : 150000000
},
"threadId" : 1,
"threadPriority" : 5
}
{code}
Entire JSON Log Message from file:
{code:java}
{
"thread" : "main",
"level" : "INFO",
"loggerName" : "com.###.analytics.framework.DataRead$",
"message" : "{id=3, event=Performance}", <<<<<This JSON Message is incorrectly handled as a string>>>>
"endOfBatch" : false,
"loggerFqcn" : "org.apache.logging.log4j.scala.Logger$",
"instant" : {
"epochSecond" : 1571337979,
"nanoOfSecond" : 468000000
},
"threadId" : 1,
"threadPriority" : 5
}{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)