Is there a way to left pad with zeroes in the rolling file appender of log4j?
For instance myfile-00001.txt
I'm using a 3rd party log processor that reads files in lexicographical order so the the files must be left padded...
I added the following in the filePattern of log4j but I get spaces.
${logPath}/myfile-%05i.txt
Log4j2 does not currently provide this out of the box. You can add a feature request on the log4j2 Jira issue tracker.
Meanwhile, as a workaround you can implement a custom lookup (https://stackoverflow.com/a/27418802/1446916) that generates a zero padded counter and use this in the filePattern of your RollingFile appender configuration.
I created a JIRA Ticket for this issue and also prepared a pull request that solves it. I would be glad if this was included in the next release of Log4j2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With