Reputation: 56
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 a 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 successfully). 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?
Upvotes: 2
Views: 1018
Reputation: 8749
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.
Upvotes: 1