我是log4j的DailyRollingFileAppender类的新手,我想使用它来执行日志文件的每日轮换,同时还想在每次触发事件触发事件时手动修改日志文件。
例如,我想在日志文件中始终将值增加一个“TOTAL COUNT:”。我怎么能这样做?
日志内容示例:
07 Oct 2011 16:57:51 [INFO ] - Failed
07 Oct 2011 16:57:51 [WARN ] - Failed
07 Oct 2011 16:57:51 [ERROR] - Successful
07 Oct 2011 16:57:51 [FATAL] - Failed
07 Oct 2011 16:57:52 [DEBUG] - Successful
07 Oct 2011 16:57:52 [INFO ] - Failed
07 Oct 2011 16:57:52 [WARN ] - Failed
07 Oct 2011 16:57:52 [ERROR] - Successful
07 Oct 2011 16:57:52 [FATAL] - Failed
07 Oct 2011 16:57:53 [DEBUG] - Successful
07 Oct 2011 16:57:53 [INFO ] - Failed
07 Oct 2011 16:57:53 [WARN ] - Failed
07 Oct 2011 16:57:53 [ERROR] - Successful
07 Oct 2011 16:57:53 [FATAL] - Failed
07 Oct 2011 16:57:54 [DEBUG] – Successful
TOTAL COUNT: 15
答案 0 :(得分:0)
subAppend()
中的DailyRollingFileAppender
似乎是最重要的。在调用super.subAppend()
时,您还必须谨慎,因为WriterAppender
会像这样实现它:
protected void subAppend(LoggingEvent event) {
this.qw.write(this.layout.format(event));
// ...
}
并且您不希望使用“TOTAL COUNT”行进行布局。
在我的subAppend()
中,我完全复制了D.R.F.Appender所做的事情,并补充道:
qw
。