Log4j is configured and does not work properly

I am using log4j for the purpose of loggin in my application. Since now I used the following code to configure logging:

LogManager.resetConfiguration();
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("log4j.properties"); 
Properties props= new Properties();
props.load(stream);
PropertyConfigurator.configure(props);

But the problem was that whenever I wanted to change the level of logging during the process, I had to restart the server. So I changed the code to: -

LogManager.resetConfiguration();
PropertyConfigurator.configureAndWatch(("log4j.properties", 900000L);

this code should ideally help reload the log4j.properties file after the specified time, which I mentioned as 15 minutes, has expired. But the code is not working yet

Am I missing during code?

Sincerely.

+5
source share
2 answers

configureAndWatch()browsing files. Not resources on the way to classes.

+7
source

! , , , .

//Resource
DOMConfigurator.configureAndWatch("/log4j.xml", 2000L);

//File
DOMConfigurator.configureAndWatch("./src/log4j.xml", 2000L);

log4j.xml !

+1

All Articles