Dave Howes created LOG4J2-1509:
----------------------------------
Summary: Log4j2 JSONLayout is not parseable on OSX
Key: LOG4J2-1509
URL: https://issues.apache.org/jira/browse/LOG4J2-1509
Project: Log4j 2
Issue Type: Question
Components: Layouts
Affects Versions: 2.6.2
Environment: Darwin DaveH.local 15.4.0 Darwin Kernel Version 15.4.0:
Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
Java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Reporter: Dave Howes
Priority: Minor
When I use the JSONLayout with 'complete=true' to write to a file, the
resulting file cannot be parsed by either json.simple or Gson
Two things appear out of the ordinary to me
1) the terminating "]" always has a blank line inserted before it in to the
file.
2) Windows style CR-LF seem to be being used for the line separators.
The JSON as written to the file is as follows :
{panel}
[^M
{
"timeMillis" : 1470831244334,
"thread" : "main",
"level" : "DEBUG",
"loggerName" : "daveLoggingCalculatorService",
"message" : "LoggingCalculatorService Entering add ",
"endOfBatch" : false,
"loggerFqcn" : "org.apache.logging.slf4j.Log4jLogger",
"contextMap" : {
"id" : "5ca2d4d5-756b-4a79-80d2-dba255fa4536",
"loginId" : "Paul Kossoff"
},
"threadId" : 1,
"threadPriority" : 5
}^M
, {
"timeMillis" : 1470831244406,
"thread" : "main",
"level" : "DEBUG",
"loggerName" : "dave.LoggingCalculatorService",
"message" : "LoggingCalculatorService Exiting add",
"endOfBatch" : false,
"loggerFqcn" : "org.apache.logging.slf4j.Log4jLogger",
"contextMap" : {
"id" : "5ca2d4d5-756b-4a79-80d2-dba255fa4536",
"loginId" : "Paul Kossoff"
},
"threadId" : 1,
"threadPriority" : 5
}^M
^M
]^M
{panel}
Both parsers fail at the line immediately preceding the terminating "]" - at
first sight it would appear that a line with only a ^M on it is identified as
being the end of stream when reading using a java.io.BufferedReader.
The following code produces the following stacktrace:
{code}
List<LinkedTreeMap> logContent = (List<LinkedTreeMap>)gson.fromJson(new
FileReader(LOG_FILE_NAME), Object.class);
{code}
{panel}
com.google.gson.JsonSyntaxException: java.io.EOFException: End of input at line
32 column 1
at com.google.gson.Gson.fromJson(Gson.java:813)
at com.google.gson.Gson.fromJson(Gson.java:741)
at .....
{panel}
If I manually remove the ^M from the file, but leave the empty line, the file
can be parsed correctly.
I'm not sure if this is a problem in the JSON parsers, the log4j2 JSONAppender,
or my ability to process files correctly in java .
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]