Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j2 left pad filename with zeroes

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

like image 892
user432024 Avatar asked Jan 28 '16 22:01

user432024


2 Answers

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.

like image 88
Remko Popma Avatar answered Sep 18 '22 04:09

Remko Popma


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.

like image 25
radlan Avatar answered Sep 21 '22 04:09

radlan