sanova opened a new issue, #2162:
URL: https://github.com/apache/logging-log4j2/issues/2162
## Description
I’m trying to set up a log reader using JsonLayout.
Everything is fine even using the JsonTemplateLayout class and replicating
the JsonLayout json structure and removing unnecessary properties.
However, if the log has a stackTrace, the string is not parsed. The same
problem occurs even when using JsonLayout directly, both with stringified
stackTrace and without.
## Configuration
appender.filejson.layout.type = JsonLayout
appender.filejson.layout.compact = true
appender.filejson.layout.eventEol = true
appender.filejson.layout.complete = false
appender.filejson.layout.properties = false
appender.filejson.layout.propertiesAsList = false
appender.filejson.layout.locationInfo = true
appender.filejson.layout.includeStacktrace = true
appender.filejson.layout.stacktraceAsString = true
appender.filejson.layout.includeNullDelimiter = false
appender.filejson.layout.objectMessageAsJsonObject = true
**Version:** [Log4j version]
Version: 2.20.0
**Operating system:** [OS and version]
Debian 10
**JDK:** [JDK distribution and version]
java version "1.8.0_221
## Logs
Caused by: java.lang.IllegalArgumentException: argument "content" is null
at
[email protected]//com.fasterxml.jackson.databind.ObjectReader._assertNotNull(ObjectReader.java:2366)
at
[email protected]//com.fasterxml.jackson.databind.ObjectReader.createParser(ObjectReader.java:1099)
at
[email protected]//com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1491)
at
deployment.basiccore.war//org.apache.logging.log4j.core.parser.AbstractJacksonLogEventParser.parseFrom(AbstractJacksonLogEventParser.java:38)
at
deployment.basiccore.war//org.apache.logging.log4j.core.parser.JsonLogEventParser.parseFrom(JsonLogEventParser.java:25)
at
deployment.basiccore.war//it.siag.basiccore.logs.LogManager.getLogByDates(LogManager.java:100)
... 203 more
## Reproduction
Example json log string:
```
{
"instant": {
"epochSecond": 1704362220,
"nanoOfSecond": 253185000
},
"thread": "default task-1",
"level": "DEBUG",
"loggerName": "it.siag.basiccore.logs.LogManager",
"message": "Error retrieving log.. ",
"thrown": {
"commonElementCount": 0,
"name": "java.lang.NullPointerException",
"extendedStackTrace": [
{
"class": "it.siag.basiccore.logs.LogManager",
"method": "getLastLogRows",
"file": "LogManager.java",
"line": 63,
"exact": false,
"location": "classes",
"version": "?"
},
<.............>
<.............>.
{
"class": "java.lang.Thread",
"method": "run",
"file": "Thread.java",
"line": 834,
"exact": true,
"location": "?",
"version": "?"
}
]
},
"endOfBatch": false,
"loggerFqcn": "org.apache.logging.log4j.spi.AbstractLogger",
"threadId": 150,
"threadPriority": 5,
"source": {
"class": "it.siag.basiccore.logs.LogManager",
"method": "getLastLogRows",
"file": "LogManager.java",
"line": 72,
"classLoaderName": "deployment.basiccore.war"
}
}
```
Code to parse line:
```
JsonLogEventParser parser = new JsonLogEventParser();
try (BufferedReader br = new BufferedReader(new FileReader(logFilePath))) {
while (br.readLine() != null) {
// Get LOG Event from line
try {
LogEvent logEvent = parser.parseFrom(br.readLine());
.....
}
catch(Exception x) {
System.out.print("Error parsing log");
throw x;
}
}
}
catch(Exception e) {
System.out.println(e.getStackTrace().toString());
throw new RuntimeException(e);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]