users@glassfish.java.net

Commons Logging and Log4J

From: <glassfish_at_javadesktop.org>
Date: Fri, 22 Aug 2008 01:06:08 PDT

Hello Forum.

The current project (originally developed on JBoss) I'm working on has the necessity to stick with Log4J (Political decision). To become a little bit more independent Apache Commons Logging shall be introduced within the new code and subsequently replace the plain Log4J code within the older modules.

After doing quite a while of web research I was able to get Apache Commons Logging and Log4J to
work on the Glassfish v2 ur2. I hope that someone in this Forum can solve the remaining questions...

The test application is a simple web app and the deployed war file has the following structure:

testApp.war
  - WEB-INF
      - classes
          - commons-logging.properties
          - log4j.xml
     - lib
          - log4j-1.2.14.jar
          - commons-logging-1.1.1.jar

     - web.xml
     - ...

Using this method it is necessary to restart the whole Glassfish server to detect changes within the Log4J configuration file (I assume Glassfish loads some Log4J classes on first usage and they simply remain in memory) even after the application is redeployed.
Is there any way to reload the configuration at run time?

The other thing is that using the "org.apache.log4j.ConsoleAppender" named STDOUT stops working after another application is deployed on the server (I deployed the "roller" web log app for testing purposes). After deploying the second app one can see the message "log4j:ERROR Attempted to append to closed appender named [STDOUT]."
Does any one have a tip for that?

In conclusion I can say configuring an alternative logging system seems quite clumsy - alt least in the way I achieved it so far.
In this thread (http://tinyurl.com/6jhs88) someone suggests:
"
You want Glassfish system logs to log through Log4j? Add a LogManager, and a Logger implementation that routes through Log4j. There, shazam, all of Glassfish is running through Log4j, and it doesn't even know about it. No need to recode Glassfish, no need to convert anything. You change a property on the command line and Everything is Different while still being oh so familiar."

Does someone here can explain that to me in more detail or point me to some documentation about it?

Any help would be greatly appreciated...

Thanks in advance,

Henning
[Message sent by forum member 'henningmalzahn' (henningmalzahn)]

http://forums.java.net/jive/thread.jspa?messageID=294730