1

Is it possible to add or override log4j configuration previously loaded by log4j.xml file with another log4j.xml file loaded at runtime ?

My Glassfish server loads at startup log4j.xml file and I would like to change this configuration with another log4j.xml file in EAR file.

I tried to use DOMConfigurator.configure("log4j.xml") but it seems that the previously configuration is not overrided (but this method find log4j.xml file because when I change to non existing file, I have Exception).

How can I do this please ?

1 Answer 1

2

A log4j Configurator always applies its configuration starting from the "current" settings. If you want the new settings to replace the old ones, simply call LogManager.resetConfiguration() first, before calling the DOMConfigurator.

Sign up to request clarification or add additional context in comments.

2 Comments

I tested it before but for my case, it doesn't work. Context is : log4j.xml loaded at Glassfish startup and I want this file to be overrided by another log4j.xml file in EAR project. I test this inside servlet which is loaded at startup (<load-on-startup> 1 </load-on-startup>)
Ok, I've found the problem. DOMConfigurator.configureAndWatch("log4j.xml"); loads the log4j.xml file in Glassfish (the one already loaded...) not the new in my EAR, I don't know why

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.