In the case of a log being deleted, log4j How to configure a new log to be created automatically

Source: Internet
Author: User
Tags log4j

"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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.