log4j2 creates empty log file when configuration happens

1.1k views Asked by At

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.

1

There are 1 answers

1
sazzad On BEST ANSWER

You need to set the value of createOnDemand parameter to true, which is false 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.