user432024
user432024

Reputation: 4675

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

Upvotes: 5

Views: 1265

Answers (2)

radlan
radlan

Reputation: 2563

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.

Upvotes: 2

Remko Popma
Remko Popma

Reputation: 36834

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.

Upvotes: 3

Related Questions