This post will explain how to separate your log4j logs when having the same WARs deployed multiple times (packaged in an EAR) on the same JBoss.
For example myApp1.war and myApp1_copy.war.
This post is for JBoss EAP 4.3 ! For EAP 5.0.0 it does not work ! For EAP 5.1 you will not need this as it becomes simpler DeployURL equals the specific war name. (see end of post)
Main article:
While looking for a solution you will most likely find the wiki entry on jboss.org: http://community.jboss.org/wiki/SeparatingApplicationLogs
Unfortunately it does not cover the need to separate logging when having multiple equivalent WARs that log via the same class --> example1 (or that use a common .jar that does the logging --> example2)
example1.ear
├── myApp1.war
├── myApp1_copy.war
└── META-INF
├── application.xml
└── jboss-app.xml
example2.ear
├── myApp1.war
├── myApp1_copy.war
├── loggingJar.jar
└── META-INF
├── application.xml
└── jboss-app.xml
The log that you would want to see is:
Adapting your log4J within JBoss
JBoss logging gives you the possibility to add filters within the jboss-log4j.xml file via the TCLFilter class. For the following DeployURL parameter it is usually sufficient to add a sub string of the deployed WAR name "myApp1-exp.war" (found in your JBOSS/server/<profile>/tmp/deploy directory). For our scenario this is not sufficient, we have to add /WEB-INF at the end of the string. If we do not add /WEB-INF we will get logs in both log files! The reason is that the TCLFilter class compares the value of DeployURL with the repositories of the Classloader ...
By the way if you want that JBoss takes changes of your jboss-log4j.xml into account immediately you'll want to set
The filter of your appender should look like this :
To make sure that
myApp1.war logs into JBOSS/server/<profile>/log/myApp1.log
and
example1.ear
├── myApp1.war
├── myApp1_copy.war
└── META-INF
├── application.xml
└── jboss-app.xml
example2.ear
├── myApp1.war
├── myApp1_copy.war
├── loggingJar.jar
└── META-INF
├── application.xml
└── jboss-app.xml
The log that you would want to see is:
JBOSS/server/<profile>/log/myApp1.log
JBOSS/server/<profile>/log/myApp1_copy.log
Adapting your log4J within JBoss
JBoss logging gives you the possibility to add filters within the jboss-log4j.xml file via the TCLFilter class. For the following DeployURL parameter it is usually sufficient to add a sub string of the deployed WAR name "myApp1-exp.war" (found in your JBOSS/server/<profile>/tmp/deploy directory). For our scenario this is not sufficient, we have to add /WEB-INF at the end of the string. If we do not add /WEB-INF we will get logs in both log files! The reason is that the TCLFilter class compares the value of DeployURL with the repositories of the Classloader ...
By the way if you want that JBoss takes changes of your jboss-log4j.xml into account immediately you'll want to set
The filter of your appender should look like this :
<filter class="org.jboss.logging.filter.TCLFilter">
<param name="AcceptOnMatch" value="true"/>
<param name="DeployURL" value="myApp1-exp.war/WEB-INF"/>
</filter>
To make sure that
myApp1.war logs into JBOSS/server/<profile>/log/myApp1.log
and
myApp1_copy.log logs into JBOSS/server/<profile>/log/myApp1_copy.log
add the following into your jboss-log4j.xml:
<appender name="APPENDER-1" class="org.jboss.logging.appender.FileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.home.dir}/log/web1.log"/>
<param name="Append" value="false"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value=" %r [%t] %-5p %c %x - %m%n"/>
</layout>
<filter class="org.jboss.logging.filter.TCLFilter">
<param name="AcceptOnMatch" value="true"/>
<param name="DeployURL" value="myApp1-exp.war/WEB-INF"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"></filter>
</appender>
<appender name="APPENDER-2" class="org.jboss.logging.appender.FileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.home.dir}/log/web2.log"/>
<param name="Append" value="false"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value=" %r [%t] %-5p %c %x - %m%n"/>
<!--param name="ConversionPattern" value="%d %-5p [%c] %m%n"/-->
</layout>
<filter class="org.jboss.logging.filter.TCLFilter">
<param name="AcceptOnMatch" value="true"/>
<param name="DeployURL" value="myApp1_copy-exp.war/WEB-INF"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"></filter>
</appender>
<category name="com.your.package">
<priority value="DEBUG" />
<appender-ref ref="APPENDER-1"/>
<appender-ref ref="APPENDER-2"/>
</category>
The different JBoss EAP versions differ as the deployment process changes from each version:
EAP4.3:
<param name="DeployURL" value="myApp1-exp.war"/>
EAP5.0.0:
TCLFilter does not work at all here is the issue : https://issues.jboss.org/browse/JBAS-6532
EAP5.1: the TCLFilter can be set up with the name of the war
<param name="DeployURL" value="myApp1.war"/>
<appender name="APPENDER-1" class="org.jboss.logging.appender.FileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.home.dir}/log/web1.log"/>
<param name="Append" value="false"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value=" %r [%t] %-5p %c %x - %m%n"/>
</layout>
<filter class="org.jboss.logging.filter.TCLFilter">
<param name="AcceptOnMatch" value="true"/>
<param name="DeployURL" value="myApp1-exp.war/WEB-INF"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"></filter>
</appender>
<appender name="APPENDER-2" class="org.jboss.logging.appender.FileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.home.dir}/log/web2.log"/>
<param name="Append" value="false"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value=" %r [%t] %-5p %c %x - %m%n"/>
<!--param name="ConversionPattern" value="%d %-5p [%c] %m%n"/-->
</layout>
<filter class="org.jboss.logging.filter.TCLFilter">
<param name="AcceptOnMatch" value="true"/>
<param name="DeployURL" value="myApp1_copy-exp.war/WEB-INF"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"></filter>
</appender>
<category name="com.your.package">
<priority value="DEBUG" />
<appender-ref ref="APPENDER-1"/>
<appender-ref ref="APPENDER-2"/>
</category>
The different JBoss EAP versions differ as the deployment process changes from each version:
EAP4.3:
<param name="DeployURL" value="myApp1-exp.war"/>
EAP5.0.0:
TCLFilter does not work at all here is the issue : https://issues.jboss.org/browse/JBAS-6532
EAP5.1: the TCLFilter can be set up with the name of the war
<param name="DeployURL" value="myApp1.war"/>
No comments:
Post a Comment