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

Reply via email to