I have recently upgraded to log4j2 and find that log4j creates empty log files for all my rolling file appenders when the java process starts up and initializes the log4j context. So, even if some of my job threads are not running, they have empty log files created for the related appenders.
Is there a way to postpone the creation of log file to the time when first LogEvent is triggered?
P.S. - I have seen How do I make log4j create log files on demand only? But it did not help much.
You need to set the value of
createOnDemand
parameter totrue
, which isfalse
by default.Note: This feature is supported from Log4j-2.7. So if you are using some older version, you will need to upgrade in order to use this feature.