是否可以在Tomcat中动态地重新加载log4j.xml/log4j.properties文件? [英] Is it possible to reload log4j.xml / log4j.properties file dynamically in Tomcat?

查看:275
本文介绍了是否可以在Tomcat中动态地重新加载log4j.xml/log4j.properties文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是,每当更改log4j.properties/log4j.xml时,都需要重新启动tomcat [或说其他任何服务器].有没有重新加载log4j配置的解决方法?

The problem is, whenever you change the log4j.properties/log4j.xml, you need to restart the tomcat [ or say any other server ]. Is there any workaround of reloading the log4j configuration?

推荐答案

来自 http ://logging.apache.org/log4j/1.2/faq.html#3.6

有没有一种方法可以将log4j 自动重新加载配置 文件是否更改?

Is there a way to get log4j to automatically reload a configuration file if it changes?

是的. DOMConfigurator和 PropertyConfigurator支持自动 通过重新加载 configureAndWatch方法.请参阅 API文档了解更多 详细信息.

Yes. Both the DOMConfigurator and the PropertyConfigurator support automatic reloading through the configureAndWatch method. See the API documentation for more details.

因为configureAndWatch启动 一个单独的wathdog线程,并且因为 没有办法停止该线程 log4j 1.2,configureAndWatch 方法在J2EE中使用是不安全的 应用程序所在的环境 回收的.

Because the configureAndWatch launches a separate wathdog thread, and because there is no way to stop this thread in log4j 1.2, the configureAndWatch method is unsafe for use in J2EE envrironments where applications are recycled.

说,我已经在Java EE环境(Sun One Web Server,而不是Tomcat)中成功使用了PropertyConfigurator#configureAndWatch方法.

Said that, I've successfully used PropertyConfigurator#configureAndWatch method in a Java EE environment (Sun One Web Server, not Tomcat).

这篇关于是否可以在Tomcat中动态地重新加载log4j.xml/log4j.properties文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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