Java – use MDC to dynamically name log files in log4j

Is it possible to use MDC to name log files at run time

I have a web application that uses Tomcat docbase and calls with different names at the same time So I need a separate log file for each file

Solution

This can be done in logback, the successor of log4j

Refer to the documentation for the shifting appender

In this example, they generate separate log files for each user based on the MDC value You can use other MDC values according to your needs

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>