如何重新执行Log4j“默认初始化过程”? [英] How to Re-Execute Log4j "Default Initialization Procedure"?

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

问题描述

在运行时,我经常创建/修改 log4j 记录器,附加器,级别,布局和时间,需要将所有内容重置为默认值。



Log4j 系统已明确定义 默认初始化过程 是在将 log4j 类加载到内存时执行的。



我发现了几个 resetConfiguration() log4j 文档中的方法,但不确定是否有任何方法会执行 Default Initialization Procedure




  • BasicConfigurator.resetConfiguration / code>

  • Hierarchy.resetConfiguration();

  • LogManager.resetConfiguration();



重置任何其他建议 log4j <强>配置更受欢迎!谢谢。

解决方案

根据 doConfigure 方法的文档



从文件读取配置。 现有配置未清除或重置。如果您需要不同的行为,请在调用doConfigure 之前调用 resetConfiguration 方法。



所以我相信调用 LogManager.resetConfiguration()并调用与启动时相同的文件的 PropertyConfigurator.configure()
$ 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“默认初始化过程”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆