MDC to log entire dynamic message, irrespective of no of entries in MDC

前提是你 提交于 2020-01-25 06:51:17

问题


I want to use MDC for logging for that I'm doing

 MDC.put("ReportName", "IOR_Report");
 MDC.put("ReportJNDI", JNDI_NAME.getValue());
 log.info("Report logger working");

And added below entry in log4j.properties and it's printing correct ReportName="My ReportName" JNDI=MYJNDI

log4j.appender.REPORTSLOG = org.apache.log4j.RollingFileAppender
log4j.appender.REPORTSLOG.layout = org.apache.log4j.PatternLayout
log4j.appender.REPORTSLOG.File = ../logs/ReportLog.log
log4j.appender.REPORTSLOG.Threshold=INFO
log4j.appender.REPORTSLOG.layout.ConversionPattern=%m - ReportName=%X{ReportName} JNDI=%X{ReportJNDI}%n

But I want to add these parameters to MDC dynamically,and so don't want to hardcode like below

ReportName=%X{ReportName} JNDI=%X{ReportJNDI}%n

It should show all MDC parameters which are added in MDC, something like below I'm expecting but it's not working, what m I missing here?

 log4j.appender.REPORTSLOG.layout.ConversionPattern=%m - %X - %n

来源:https://stackoverflow.com/questions/59618615/mdc-to-log-entire-dynamic-message-irrespective-of-no-of-entries-in-mdc

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