2
votes

I'm using a RollingFile Appender with both Time(daily) and Size Trigger Policies. The filePattern ( used for renaming the file on rollover) contains:

filePattern="app-${sys:node}-%d{yyyyMMdd}-%i" 

I would like to add a random id ( ideally an uuid) to the rolled file name. Normally, the date pattern and the integer counter would be enough to unique identify a file...but in my situation the logs are automatically picked up via ftp (and deleted if transferred succesfully). Because of the file deletion it is possible to end up with a duplicate file ( on the ftp , not locally) ... because the %i counter is based on the files that already exist locally.

For instance, having:

  • app-20180205-1.log
  • app-20180205-2.log
  • app-20180205-3.log

and log4j2 currently writing to , let's say : /tmp/app.log

If the 3 files already rolled are transfered via ftp and deleted , on the next rollover , I will have app-20180205-1.log instead of app-20180205-4.log . This is what I'm trying to avoid.

Any solutions?

1
Maybe it will be easier, to delete whole day only to prevent this to happen...Betlista

1 Answers

0
votes

Instead of a UUID, you can use a more specific date-time file pattern with a more specific time resolution instead, like so:

filePattern="logs/log4j2-demo-%d{yyyy-MM-dd-HH-mm-ss}-%i.log

When your Time/Trigger policies are met, it will create a new file with this more specific date-time stamp which should always be unique per the time resolution you specify.