How to add the date timestamp to log4j2 logfiles?

membersound picture membersound · Jul 28, 2015 · Viewed 14.3k times · Source

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?

Answer

Bishal Gupta picture Bishal Gupta · Jun 20, 2016

To append the filename with date, replace %d with below format, i was having the same problem and but got by doing so :

<RollingFile name="APP" fileName="application-${date:yyyy-MM-dd}.log" />