Does log4j support JSON format?

前端 未结 4 1281
鱼传尺愫
鱼传尺愫 2021-02-01 03:17

Is it possible to let log4j output its logging in JSON format by only altering the log4j.properties.xml configuration file?
I make use of an old application tha

4条回答
  •  盖世英雄少女心
    2021-02-01 03:57

    this is official JSON layout

    https://github.com/logstash/log4j-jsonevent-layout

    1) Add maven dependency https://mvnrepository.com/artifact/net.logstash.log4j/jsonevent-layout

    
        net.logstash.log4j
        jsonevent-layout
        1.7  
    
    

    2) Add configuration to your log4j.properties file

     log4j.rootCategory=WARN, RollingLog
     log4j.appender.RollingLog=org.apache.log4j.DailyRollingFileAppender
     log4j.appender.RollingLog.Threshold=TRACE
     log4j.appender.RollingLog.File=api.log
     log4j.appender.RollingLog.DatePattern=.yyyy-MM-dd
     log4j.appender.RollingLog.layout=net.logstash.log4j.JSONEventLayoutV1
    

提交回复
热议问题