'How to configure log4j 1.2.7 for an application having multiple WAR files under Jboss/Wildfly?

I want to configure log4j to get logs in a separate log file rather than the server.log file with having multiple WAR files in place. Let's say, I have two WAR files where war-A is the starting point (signup / login etc.) and then the war-B comes. Both are linked with each other. War-A is the general starting point for an EAP. log4j-A.xml of war-A has configurations to write logs into "ABC.logs" while log4j-B.xml of war-B has configurations to write logs into "XYZ.logs".

Now, the log4j is working but it is writing all the logs (of war-A and war-B) into the log file of war-A which is "ABC.logs". I want to switch to the configurations of war-B to write that logs into "XYZ.logs" as soon as have move from war-A (e.g. on next page after login).

I am using Wildfly 9.0.2 as my application server and it is initializing log4j from "C:\wildfly9.0.2\standalone\tmp\vfs\temp\temp89993ff21\content-f176534\WEB-INF\classess\log4j-A.xml" every time.

Suppose, I have only access or can do changes in War-B because some other team is working on War-A (I can just deploy WAR-A and have that as starting point for my WAR-B), how can I achieve it to do logging in my desired file "XYZ.logs" as soon as my WAR application has started?

One more thing that I would like to mention is that if I build and deploy my WAR-B and then starts the application then the Wildfly picks log4j-B.xml as configuration file and do the right logging (but in this case, it writes the logs of WAR-A as well).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source