Remove log4j2 default fields in JsonLayout logs
I’m trying to customize log4j2
output. For example, the default log is:
{ "instant": { "nanoOfSecond": 943000000, "epochSecond": 1594798374 }, "level": "INFO", "threadId": 13, "host": "xxx.xxx.xxx.xxx", "@timestamp": "2020-07-15T07:32:54.940Z", "thread": "restartedMain", "spanId": "xxxxxxxxxxxxxxxx", "message": "Started AppApplication in 151.183 seconds (JVM running for 152.944)", "traceId": "xxxxxxxxxxxxx", "threadPriority": 5, "appName": "app-service", "port": 54829, "@version": "1", "date": "15-Jul-2020 14:32:54,943", "loggerName": "xxxxxxxxxxxxxxxxxxxxx", "loggerFqcn": "org.apache.commons.logging.LogAdapter$Log4jLog", "endOfBatch": false }
Some of these attributes are added by log4j2
, like: loggerName
, threadId
, loggerFqcn
, etc. And I want to log only needed data, for instance:
{ "host": "xxx.xxx.xxx.xxx", "spanId": "xxxxxxxxxxxxxxxx", "message": "Started AppApplication in 151.183 seconds (JVM running for 152.944)", "traceId": "xxxxxxxxxxxxx", "appName": "app-service", }
How can I achieve this with customizing appender or customizing layout?