ramazanpolat commented on pull request #335:
URL: https://github.com/apache/logging-log4j2/pull/335#issuecomment-683172100


   @vy One quick question: Will `JsonTemplateLayout` have the ability to 
jsonify the message object passed to Logger?
   
   e.g: Currently with using JsonLayout, this code:
   ```java
     logger.info("This is an info message");
   ```
   produces something like this:
   ```json
   {
     "timeMillis" : 1598613343782,
     "thread" : "main",
     "level" : "INFO",
     "loggerName" : "com.example.Test",
     "message" : "This is an info message",
     "endOfBatch" : false,
     "loggerFqcn" : "org.apache.logging.log4j.spi.AbstractLogger",
     "contextMap" : { },
     "threadId" : 1,
     "threadPriority" : 5
   }
   ```
   But if we pass an object to the logger like this (considering the object 
constructor is `MyDummyEventBean(String msg, String user, String ip)`:
   ```java
     logger.error(new MyDummyEventBean("Something bad happened", "john", 
"10.1.2.3");
   ```
   JsonLayout gets appends `.toString()` result of the `MyDummyEventBean` and 
produces this:
   ```json
   {
     "timeMillis" : 1598613343782,
     "thread" : "main",
     "level" : "INFO",
     "loggerName" : "com.example.Test",
     "message" : "{\"message\":\"Something bad 
happened\",\"userId\":\"john\",\"ip\":\"10.1.2.3\"}"
     "endOfBatch" : false,
     "loggerFqcn" : "org.apache.logging.log4j.spi.AbstractLogger",
     "contextMap" : { },
     "threadId" : 1,
     "threadPriority" : 5
   }
   ```


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to