java – 在log4j中使用MDC动态命名日志文件

前端之家收集整理的这篇文章主要介绍了java – 在log4j中使用MDC动态命名日志文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是否有可能在运行时使用MDC命名日志文件.

我有一个Web应用程序,使用tomcat docbase同时使用不同的名称调用.所以我需要为每个文件都有单独的日志文件.

@R_502_323@

这可以在 Logback,Log4J的继承者中完成.

Logback is intended as a successor to the popular log4j project,picking up where log4j leaves off.

请参阅Sifting Appender的文档

The SiftingAppender is unique in its capacity to reference and configure nested appenders. In the above example,within the SiftingAppender there will be nested FileAppender instances,each instance identified by the value associated with the “userid” MDC key. Whenever the “userid” MDC key is assigned a new value,a new FileAppender instance will be built from scratch. The SiftingAppender keeps track of the appenders it creates. Appenders unused for 30 minutes will be automatically closed and discarded.

在该示例中,它们基于MDC值为每个用户生成单独的日志文件.可以根据您的需要使用其他MDC值.

猜你在找的Java相关文章