4 messages in org.apache.logging.log4j-userRE: Property Configurator
FromSent OnAttachments
Viv KapJun 11, 2004 3:40 pm 
Donald LarmeeJun 13, 2004 7:01 pm 
Viv KapJun 13, 2004 9:43 pm 
Donald LarmeeJun 14, 2004 5:45 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:RE: Property ConfiguratorActions...
From:Donald Larmee (dlar@alterthought.com)
Date:Jun 13, 2004 7:01:16 pm
List:org.apache.logging.log4j-user

Viv,

The jBoss behavior is not only as a result of the container using log4j for its own internal logging, but as a consequence of the jBoss Unified ClassLoader methodology, whereby they _intentionally_ share jars across applications that have been loaded by the container. Some people see this as a benefit; some as, umm, not.

Anyway, If you wish to force jBoss to behave a bit more like most J2EE containers (and therefore avoid the whole property configurator bit) you can try the following approaches...

ASSUMPTIONS: - You are using jBoss v3.2.x - You are interested in using log4j from w/in a WebApp, from your references to WEB-INF/classes & tomcat

SOLUTION #1: Put your war in an ear file.

1.1- Plan on packaging your war file INSIDE an ear (myapp.ear, for purposes of this discussion) 1.2- In addition to placing your log4j.properties (or .xml) file in the WEB-INF/classes, place the log4j.jar file itself into the WEB-INF/lib dir. 1.3- Provide a jboss-app.xml file that packaged into your ear and looks something like the following:

<jboss-app>

<!-- The following provides EAR level scoping of classloading (i.e., J2EE style) --> <loader-repository> com.adc.affiliate:loader=myapp.ear </loader-repository>

</jboss-app>

SOLUTION #2: Tweak the embedded Tomcat ClassLoading model w/in jBoss

2.1- Modify the $JBOSS_HOME/server/$MY_SERVER/deploy/jbossweb-tomcat41.sar/META-INF/jboss-se rvice.xml to change the ClassLoading compliance model...

<server>

<mbean code="org.jboss.web.tomcat.tc4.EmbeddedTomcatService" name="jboss.web:service=WebServer">

<!-- Get the flag indicating if the normal Java2 parent first class loading model should be used over the servlet 2.3 web container first model. --> <attribute name="Java2ClassLoadingCompliance">false</attribute> ... ... </server>

SOLUTION #3: Use the suite of classes included in the log4j sandbox distribution (org.apache.log4j.servlet.*) to bootstrap log4j (InitServlet and InitContextListener)

FWIW, I use approach #1 when I can.

Hope it helps,

-Don

-----Original Message----- From: Viv Kap [mailto:vivk@yahoo.com] Sent: Friday, June 11, 2004 6:40 PM To: log4@logging.apache.org Subject: Property Configurator

Hi I have a J2EE application and we use log4j for logging. We used log4j.properties files and packaged it in a war under WEB-INF/classes. It all worked fine under Weblogic, Tomcat etc. But now when we migrated to JBoss it has its own log4j.xml file. So our application grabbed it as the first one and did not load our log4j.properties. I got around it by using -Dlog4j.configuration=log4j.properties in the startup command. But I really dont like this soultion because this system property will now be applicabe to all applications on JBOSS and thats not a good thing. Now we are plannning to use our own name like log4j-productName.properties file and make use of PropertyConfigurator. From the startup command we will pass the directory name containg config files : example -Dproduct.config=c:/config . In this we will have the log4j-product.properties file. And we will load it and use PropertyConfigurator. But this is not working exactly. When we start the server it gives all sort of exception. where should I exactly use the PropertyConfigurator ? In a static block ? This is what I have

String path = System.getProperty("config.home"); Properties p = new Properties(); try { FileInputStream fis = new FileInputStream(path + "/log4j-product.properties"); p.load(fis); } catch (FileNotFoundException e) { e.printStackTrace(); //To change body of catch statement use Options | File Templates. } catch(java.io.IOException ie) { ie.printStackTrace(); }

PropertyConfigurator.configure(p);

I get this error: 04-06-11 15:32:53,924 INFO [STDOUT] log4j:ERROR "org.jboss.logging.util.OnlyOnceErrorHandler" was loaded by [org.jboss.system.server.NoAnnotationURLClassLoader@12b6651]. 2004-06-11 15:32:53,924 DEBUG [org.jboss.mx.loading.UnifiedClassLoader] New jmx UCL with url null 2004-06-11 15:32:53,924 DEBUG [org.jboss.mx.loading.UnifiedClassLoader] setRepository, r=org.jboss.mx.loading.HeirarchicalLoaderRepository3@cee271, ucl=org.jboss.mx.loading.UnifiedClassLoader3@d9ceea{ url=null ,addedOrder=0} 2004-06-11 15:32:53,924 DEBUG [org.jboss.mx.loading.UnifiedClassLoader] New jmx UCL with url null 2004-06-11 15:32:53,924 DEBUG [org.jboss.mx.loading.UnifiedClassLoader] setRepository, r=org