How to create Custom Rolling File appender in log4j2 - customized file name
Asked Answered
C

0

1

I would like to create the log files using log4j2.

My requirement: I have to use the same log file name like below even when rolling the file (once it reaches 5MB). Please note, i have to use the same timestamp (110923) until the server runs continuously.

LogFileName_110923_1.log  
LogFileName_110923_2.log, etc  

When the server restarts I will have to create new log file with different timestamps. Like,

LogFileName_1834345_1.log  
LogFileName_1834345_2.log, etc

I think i have to use custom rolling file appender. But I don't know how to achieve it in log4j2.

Please assist me.

Chad answered 16/1, 2017 at 3:33 Comment(1)
Do you need the logs written to files with those names are can you write to app.log and rollover to files with that name? In either case you want to use the SizeBasedTriggeringPolicy to rollover when the file reaches 5MB. If you need to write directly to files with that file pattern you will have to wait for Log4j 2.8 to be released as that feature was just added. If you can write to app.log and only have the archives match that name you can do that now.Messiah

© 2022 - 2024 — McMap. All rights reserved.