"Preface" If the log specified in the configuration file is deleted, log4j does not automatically generate a new log to continue writing the log. Log4j whether there is a related configuration, you can automatically create a new log if the log is deleted.
"Answer" should not be.
I am curious to see the source code of log4j, for such a situation, log4j will not create a new log file, but will output error information to the System.err
/** This method determines if there was a sense in attempting to append. <p>it checks whether there is a set output target and also if there is a set layout. If These are checks fail, then the Boolean value <code>false</code> is returned. */protected Boolean checkentryconditions () {if (this.closed) {Loglog.warn ("not allowed to write to a closed appender.") ; return false; } if (this.qw = = null) {errorhandler.error ("No output stream or file set for the appender named [" + name+ "]."); Se } if (this.layout = = null) {errorhandler.error ("No layout set for the appender named [" + name+ "]."), return false;} retur n true; }
So in this case, I think there are two ways to solve this problem:
1) Another scheduled task, listening to the log
2 in Getlog or getinstance (single piece mode) to increase the judgment, check the log4j configuration file in the log file exists, if it does not exist on the new init log4j