log4j reset properties back to original as in log4j.properties file

随声附和 提交于 2019-12-06 05:11:10

As stated in my comments above both

LogManager.resetConfiguration();
PropertyConfigurator.configure(prop);

don't reconfigure already existing Logger instances, so that they still use your old EmailAppender. In order to make changes to take effect you should recreate loggers. If it's not possible (your loggers are static final fields for example), you can create a simple Logger wrapper, which will register itself with some listener, that will notify on configuration change, so that wrapper can create fresh logger instance

This is a partial answer (I know); But you can do a reset without explicit LogManager.resetConfiguration();

Resetting Hierarchy

The hierarchy will be reset before configuration when log4j.reset=true is present in the properties file.

https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!