You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2020/09/01 15:23:32 UTC

[GitHub] [logging-log4j2] ramazanpolat commented on pull request #335: Import of LogstashLayout as JsonTemplateLayout

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


   @vy Sorry but `LogstashLayout` spits my object's as toString() output:
   
   ```json
   {
     "line" : 123,
     "class" : "tr.gov.sgk.logclient.DAO",
     "message" : "MyLogBean2{message='LogBean Message', userId='LogBean userId', ip='LogBean IP'}",
     "level" : "ERROR",
     "method" : "errorWithExceptionLogstash1",
     "logger" : "logstashLogger"
   }
   ```
   Maybe I'm doing something wrong. My `LogstashJsonEventLayoutV1.son` file:
   ```json
   {
     "line": "${json:source:lineNumber}",
     "class": "${json:source:className}",
     "message": "${json:message:json}",
     "level": "${json:level}",
     "method": "${json:source:methodName}",
     "logger": "${json:logger:name}"
   }
   ```
   My `LogstashLayout` in `log4j2.xml`:
   ```xml
   <LogstashLayout eventTemplateUri="classpath:LogstashJsonEventLayoutV1.json"
                   prettyPrintEnabled="true"
                   locationInfoEnabled="true"
                   stackTraceEnabled="true" />
   ```
   The class I want to be printed as Json(**maybe this class needs to implement an interface?**):
   ```java
   public class MyLogBean2 {
       private String message;
       private String userId;
       private String ip;
   
       public MyLogBean2() {    }
   
       public MyLogBean2(String message, String userId, String ip) {
           this.message = message; this.userId = userId; this.ip = ip;
       }
   
       public String getMessage() { return message;}
   
       public void setMessage(String message) {this.message = message;}
   
       public String getUserId() {return userId;}
   
       public void setUserId(String userId) {this.userId = userId;}
   
       public String getIp() {return ip;}
   
       public void setIp(String ip) {this.ip = ip;}
   
       @Override
       public String toString() {
           return "MyLogBean2{" +
                   "message='" + message + '\'' +
                   ", userId='" + userId + '\'' +
                   ", ip='" + ip + '\'' +
                   '}';
       }
      
   }
   ```


----------------------------------------------------------------
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:
users@infra.apache.org