How to generate half-daily logs using log4j2?

寵の児 提交于 2021-02-10 16:41:08

问题


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}">

And also defined:

<Policies>
    <TimeBasedTriggeringPolicy interval="1" 
        Module="true"/>

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

Can somebody help me out in the same?


回答1:


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>


来源:https://stackoverflow.com/questions/36172879/how-to-generate-half-daily-logs-using-log4j2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!