Sheetal Dorby
Sheetal Dorby

Reputation: 11

How to generate half-daily logs using 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}">

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?

Upvotes: 1

Views: 4818

Answers (1)

rgoers
rgoers

Reputation: 9141

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>

Upvotes: 1

Related Questions