本文介绍了如何重新执行Log4j“默认初始化过程”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

$ b

resetConfiguration()方法记录在类。


At runtime I often create/modify log4j Loggers, Appenders, Levels, Layouts, and time to time need to reset everything back to defaults.

Log4j system has well defined Default Initialization Procedure that is executed when log4j classes are loaded into memory. Is there any way to re-execute the entire Procedure programmatically later at runtime?

I found several resetConfiguration() methods in log4j documentation, but not sure if any of them will do what the Default Initialization Procedure does:

  • BasicConfigurator.resetConfiguration();
  • Hierarchy.resetConfiguration();
  • LogManager.resetConfiguration();

Any other suggestions on resetting log4j configurations are more then welcome! Thank you.

解决方案

According to the documentation for the doConfigure method:

Read configuration from a file. The existing configuration is not cleared nor reset. If you require a different behavior, then call resetConfiguration method before calling doConfigure.

So I belive that calling LogManager.resetConfiguration() and recall PropertyConfigurator.configure() with the same files as on startup will do what you want.

The resetConfiguration() method is documented in Hierarchy class.

这篇关于如何重新执行Log4j“默认初始化过程”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 22:34