[英]Log4j configure and watch not working properly
I am using log4j for loggin purpose in my application. 我在我的应用程序中使用log4j进行登录。 Since now to configure the logging i was using the following code : 从现在开始配置日志记录我使用以下代码:
LogManager.resetConfiguration();
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("log4j.properties");
Properties props= new Properties();
props.load(stream);
PropertyConfigurator.configure(props);
But the problem with this was , that whenever i wanted to change the logging level during the process, i had to restart the server. 但问题是,每当我想在此过程中更改日志记录级别时,我必须重新启动服务器。 So i changed the code to :- 所以我将代码更改为: -
LogManager.resetConfiguration();
PropertyConfigurator.configureAndWatch(("log4j.properties", 900000L);
this code ideally should help to re-load the log4j.properties file after the time specified, which i have mentioned as 15 minutes. 理想情况下,此代码应该有助于在指定的时间后重新加载log4j.properties文件,我已经提到15分钟。 But still the code is not working 但是代码仍然没有用
Am i missing somthing during the code? 我在代码中错过了什么吗?
Regards. 问候。
configureAndWatch()
watches files. configureAndWatch()
监视文件。 Not resources in the classpath. 不是类路径中的资源。
I tried the solution and works fine! 我尝试了解决方案,工作正常! The point is that your must provide the path like a file not like a resource. 关键是你必须像文件一样提供不像资源的路径。
//Resource
DOMConfigurator.configureAndWatch("/log4j.xml", 2000L);
//File
DOMConfigurator.configureAndWatch("./src/log4j.xml", 2000L);
Try the second option and modify the log4j.xml and test it! 尝试第二个选项并修改log4j.xml并测试它!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.