本文介绍了如何使用log4j2生成半日日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过log4j2配置生成半日日志文件.我给了:
I want to generate half-daily log files through log4j2 configuration. I have given :
<RollingFile name="fileAppender" filename ="${logName} append="true"
FilePattern="${logName}. %d{yyyy-MM-dd-a}">
并且还定义了:
<Policies>
<TimeBasedTriggeringPolicy interval="1"
Module="true"/>
但我只通过这种方式登录 AM,尽管我希望它成为某种东西:
But i am getting only AM log in this way though i want it to be something :
a.log.2016-03-23-AM
b.log.2016-03-23-PM
有人可以帮我吗?
推荐答案
您可以为此使用CronTriggeringPolicy.我从以供实际使用.
You can use the CronTriggeringPolicy for this. I borrowed the expression from the answer at Cron Expression (Quartz) for a program to run every midnight at 12 am for the actual expression to use.
<RollingFile name="fileAppender" filename ="${logName} append="true" FilePattern="${logName}.$$d{yyyy-MM-dd-a}">
<CronTriggeringPolicy schedule="0 0 0,12 * * ?" />
</RollingFile>
这篇关于如何使用log4j2生成半日日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!