You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Joseph Husby (JIRA)" <ji...@apache.org> on 2018/05/30 16:32:00 UTC

[jira] [Closed] (LOG4J2-2345) JsonLayout logs malformed if toString() contains empty curly braces {}

     [ https://issues.apache.org/jira/browse/LOG4J2-2345?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Joseph Husby closed LOG4J2-2345.
--------------------------------
    Resolution: Duplicate

> 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
>            Priority: Major
>
> 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)