简体   繁体   中英

log4j configuration change listener

My application for some reasons programatically reconfigures log4j (in some circumstances), namely custom appenders are registered. However the changes are lost as soon someone edits the log4j configuration file manually. How to make sure our programatic changes to log4j configuration are not lost? Or how to get notified when log4j re-configuration happens?

The application runs on JBoss and the problem happens when its $JBOSS/server/default/conf/jboss-log4j.xml file is edited, but I believe the issue is not specific to JBoss AS at all.

You could, I suppose periodically poll the Log4j API asking if your custom appenders are attached (using Category.isAttached(appender) ), and re-attach if necessary. It's rather clunky, but I don't know of any notification mechanism for this.

Is log4j being configured by calling configureAndWatch() explicitly in your code?

If so the simple fix is to not call the "andWatch" method, just regular configure() .

Is there a reason why these custom appenders can't be configured in the properties file, rather than specially in code?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM