Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add the date timestamp to log4j2 logfiles?

Tags:

java

log4j

log4j2

I want to create day dependent logfiles with log4j2:

<RollingFile name="APP" fileName="application-%d{yyyy-MM-dd}.log" />

Resulting logfile name: application-%d{yyyy-MM-dd}.log, the timestamp is not replaced. Why?

like image 762
membersound Avatar asked Jul 28 '15 07:07

membersound


1 Answers

The pattern should not be given in the attribute "fileName" rather you have to specify the pattern in the attribute "filePattern" as like below.

<RollingFile name="RollingFile" fileName="${log-path}/filename.log" 
filePattern="${log-path}/filename-%d{yyyy-MM-dd}-%i.log" >
...
...
</RollingFile>

The "%i" is the counter that will be automatically incremented in rollover.

Hope this will help you.

like image 180
Loganathan Mohanraj Avatar answered Oct 27 '22 08:10

Loganathan Mohanraj