Context: I have two java applications (A.EAR and B.EAR) deployed in weblogic. Both applications have their own log4j jars bundled inside the EARs (packaged as maven dependencies). I have used saperate log4j.properties (a-log4j.properties and b-log4j.properties) files for both these applications and specified that they log to different log files (a.log and b.log).
Problem: When I run just the application A, I get the logs in a.log. but after a while when I start the application B, both application A and B log to b.log. Nothing else is written in a.log until a restart on A is performed. In simple terms, which ever application I start at the last all the applications logs are written into that application's logs. Does anyone know why this could be happening?
I am using WebLogic 11g and log4j 1.2.17.
Solution/Fix:
Aparently, if this is the case it means that as both web apps would share a root classloader serving the global libraries load by Weblogic, we need to specify to load the application classes after the server classes. This could be done by:
<wls:prefer-application-packages>
<wls:package-name>org.apache.log4j.*</wls:package-name>
</wls:prefer-application-packages>
In versions older than 10.3.3 like 11g you can do this as:
<prefer-application-packages>
<package-name>org.apache.log4j.*</package-name>
</prefer-application-packages>