Log4j configure and watch not working properly

99封情书 提交于 2019-12-10 14:15:01

问题


I am using log4j for loggin purpose in my application. 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. But still the code is not working

Am i missing somthing during the code?

Regards.


回答1:


configureAndWatch() watches files. Not resources in the classpath.




回答2:


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!



来源:https://stackoverflow.com/questions/7468882/log4j-configure-and-watch-not-working-properly

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