Both suggestion from the Wiki don't work. It is cheating.
I just cut and paste the code into my code, it doesn't work at all.
Yeah I couldn't get it to work either, allbeit I didn't try for very long.
It seems to be a poor feature of Log4J that you can only have one config per JVM. In the end we have to have 1 log4j config in our EAR file which has knowledge of every application deployed and the JBoss log4j config too, as you can understand this is not ideal.
the problem is not comming log4j. It's a jboss classloading problem.
In jboss4.3 sp1 version, you could have a log4j.jar version for each of you application.
But with jboss 4.2 version doing so, you may experience with exception below
log4j:ERROR A "org.jboss.logging.appender.FileAppender" object is not assignable to a "org.apache.log4j.Appender" variable. log4j:ERROR The class "org.apache.log4j.Appender" was loaded by log4j:ERROR [WebappClassLoader delegate: false repositories: /WEB-INF/classes/ ----------> Parent Classloader: java.net.FactoryURLClassLoader@18c10af ] whereas object of type log4j:ERROR "org.jboss.logging.appender.FileAppender" was loaded by [org.jboss.system.server.NoAnnotationURLClassLoader@1a33d48]. log4j:ERROR Could not instantiate appender named "FILE".
It seem not possible to override jboss server librairies (log4j.jar is present in jboss server lib and has been customised).
Even if you try to isolate classloadiing, it's not working witk log4j.
After searching on the different forums, it seems that there is no clear solution to solve this issue. With the application we are developing, the same problem occurs.
We are deploying an app1.WAR and a app2.EAR file in JBoss. Each of them has its own log4j.xml and logging occurs respectively in app1.log and app2.log.
When JBoss is started, JBoss' default server.log file is used for the logging. When app1.WAR is "activated", app1.log is used but server.log is no longer used. When app2.EAR is "activated", app2.log is used but app1.log is no longer used. This behavior seems to be totally random.
Changing JBoss' default log4j.xml file solves the above described issue, but it remains a workaround and it surprises me that JBoss does not allow an application-specific logging configuration.
What are the guidelines that should be followed to allow separate logging for each application ?
Regards, Stefan Lecho.