Tag cloud

JBoss (16) Fedora (5) Linux (4) Red Hat (4) JON (3) command line (3) 4.3 (2) JEE (2) JVM (2) Java (2) KVM (2) Oracle (2) Portal (2) Weblogic (2) installation (2) vs (2) /boot partition (1) Add-ons (1) Apache (1) Bundles (1) Business model (1) Byteman (1) CLASSPATH (1) EAP (1) EPP (1) Eclipse (1) Failover (1) Gnome (1) JAVA_OPTS (1) JBDS (1) JBoss Tools (1) JBossON (1) JConsole (1) JDK (1) JMS (1) JVM options (1) KDE (1) MBean (1) Network (1) Open Source (1) RHQ (1) Red Hat subscription (1) Thunderbird (1) Troubleshooting (1) Virtulization (1) WS (1) Webservices (1) Wireshark (1) classloading (1) clustering (1) comparison (1) debug (1) deployment (1) disable SELinux (1) disksize (1) error (1) fun (1) jboss.org (1) log (1) log4j (1) lvm (1) messaging (1) multiple WARs (1) patent FOSS (1) performance tuning (1) provisionning (1) scripting (1) services (1) switch (1) troll (1) upgrade (1) video (1) war (1) webapp (1) yum (1)

03 August 2010

Separating log4j logging having the same WAR multiple times on one JBoss EAP 4.3

Summary:
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:
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"/>

No comments:

Post a Comment