Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure log4j per deployed application in Glassfish 3?

I'm trying to use log4j to handle the logs for a web-service which is running under Glassfish 3. Most of the guides I've seen using log4j with Glassfish want me to mess around with Glassfish global settings, which I want to avoid as there will be more than one application deployed per instance of Glassfish.

Is there any way for me to have Glassfish execute a piece of code when my web service is deployed which will allow me to call DOMConfigurator and set up log4j using my XML file?

Thanks for any help!

EDIT: The answer is to place the log4j.xml file in WEB-INF/classes. In our case, it looks as if log4j remains un-configured, but logging does still actually work as expected.

like image 778
HalliHax Avatar asked Apr 21 '11 10:04

HalliHax


People also ask

Does Glassfish use log4j?

By default Glassfish does not provide Log4J support and therefore most likely any Log4J statements end up in thin air.

Where is log4j configuration file?

Sample log4j Configuration Files During Content Engine installation, two log4j sample files are placed on the system in the ContentEngine\config\samples\ folder: log4j. properties. client: A Java format file that contains client configuration settings.


1 Answers

Yes. All you need to do is deploy the log4j configuration with the component you're deploying; log4j will use the locally-scoped configuration as long as it's not being referenced in a parent classloader.

Glassfish' global settings won't factor in at all in that case.

like image 159
Joseph Ottinger Avatar answered Oct 07 '22 22:10

Joseph Ottinger