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.
configureAndWatch()
watches files. 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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With