How to log all values set in MDC in json format using log4j.properties file in log4j 1.2

霸气de小男生 提交于 2020-01-25 07:54:05

问题


I want to display all values set in MDC in log file in json format in log4j 1.2 version.

This is third party's log4j.properties file I'm modifying so I can't change anything other than this log4j.properties file, I mean I can't add any other dependency like to help this log4j to support MDC and json format.

I can print values using %X{PARAMETER_NAME} but can't get all MDC values at once.

log4j.appender.ReportsExecutionLog = org.apache.log4j.RollingFileAppender
log4j.appender.ReportsExecutionLog.layout = org.apache.log4j.PatternLayout
log4j.appender.ReportsExecutionLog.File = ../logs/ReportsExecutionLog.json
log4j.appender.ReportsExecutionLog.Threshold=INFO
#log4j.appender.ReportsExecutionLog.layout.ConversionPattern=%m - ReportName=%X{REPORT_NAME} %n

I'm looking for something like below

log4j.appender.ReportsExecutionLog.layout.ConversionPattern={"%m" - "%X" }%n

But this is not giving me anything for %X

来源:https://stackoverflow.com/questions/59634856/how-to-log-all-values-set-in-mdc-in-json-format-using-log4j-properties-file-in-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!