logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remko Popma <remko.po...@gmail.com>
Subject Re: Recursive logging issue with curly braces in JSONLayout Object's toString()
Date Tue, 29 May 2018 23:41:56 GMT
No, this is not a known issue. 
Please raise a ticket on the JIRA issue tracker for this. 

The more information about the bug, the faster it is likely to be resolved. (Adding a patch
or a pull request with unit tests is ideal.)

Remko

(Shameless plug) Every java main() method deserves http://picocli.info

> On May 30, 2018, at 8:36, Husby, Joseph P. <Joseph.P.Husby@leidos.com> wrote:
> 
> Hello log4j group,
> 
> I think we've found a bug... When using JsonLayout for our appender in 2.11.0, 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:
> 
>      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";
>                }
>        }
>      }
> 
> This produces the following output:
> 
>      [
>      {
>        "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" : 1527636365,
>          "nanoOfSecond" : 40000000
>        },
>        "contextMap" : { },
>        "threadId" : 1,
>        "threadPriority" : 5
>      }
>      ]
> 
> Note how TestObj's toString is inserted in place of its "{}", resulting in it (sort-of)
being logged twice.  Is this a known issue?
> 
> Thanks!
> Joseph Husby
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message