加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 02:59:54 所属栏目:Java 来源:网络整理
导读:是否有可能在运行时使用MDC命名日志文件. 我有一个Web应用程序,使用tomcat docbase同时使用不同的名称调用.所以我需要为每个文件都有单独的日志文件. 解决方法 这可以在 Logback,Log4J的继承者中完成. Logback is intended as a successor to the popular lo
是否有可能在运行时使用MDC命名日志文件.

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

解决方法

这可以在 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值.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读