Joseph Husby created LOG4J2-2345:
------------------------------------
Summary: JsonLayout logs malformed if toString contains empty
curly braces {}
Key: LOG4J2-2345
URL: https://issues.apache.org/jira/browse/LOG4J2-2345
Project: Log4j 2
Issue Type: Bug
Components: Appenders
Affects Versions: 2.11.0
Reporter: Joseph Husby
When using JsonLayout for our appender, an object that has "{}" in its toString
will result in a recursive output. Here is a simple code example and resulting
output to illustrate the problem:
{code:java}
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Test {
public static final Logger log = LogManager.getLogger(Test.class);
public static void main(final String[] args) {
log.info("Testing {}", new TestObj());
}
static class TestObj {
@Override
public String toString() {
return "This is my toString {} with curly braces";
}
}
}
{code}
With this log4j configuration:
{code:java}
<Configuration status="INFO">
<Appenders>
<Console
name="Console"
target="SYSTEM_OUT">
<JsonLayout
properties="true"
complete="true" />
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
{code}
Produces the following output:
{code:java}
[
{
"thread" : "main",
"level" : "INFO",
"loggerName" : "Test",
"message" : "Testing This is my toString This is my toString {} with curly
braces with curly braces",
"endOfBatch" : false,
"loggerFqcn" : "org.apache.logging.log4j.spi.AbstractLogger",
"instant" : {
"epochSecond" : 1527636451,
"nanoOfSecond" : 604000000
},
"contextMap" : { },
"threadId" : 1,
"threadPriority" : 5
}
]
{code}
Note how TestObj's toString() is inserted in place of its "{}", resulting in it
being logged twice in a malformed fashion.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)