Lyf

Live at it's simplicity

Log4j Configuration JBoss as 7.1

I had been working around this issue of setting up Log4j for an application running in JBoss AS 7.1 for some time, though there are posts in the JBoss How To , Community Post, which gives an idea on how to set it up, I would like to put down the whole picture together here for anyone who might be stuck with this issue. So here it is,

The requirement here is, to have custom log4j configuration for the application you want to be deployed(could be an ear/war) and disable default log4j configuration in JBoss AS 7.1 to be used for the application.

  • 1. Have log4j.xml in the classpath. Can be placed directly in the resources folder of any of your deployments, or placed directly in the lib folder of the EAR/WAR.
  • 2. Define jboss-deployment-structure.xml in META-INF , or in WEB-INF if war.
  • 3. Exclude log4j module to be used for your deployments by specifying it in the jboss-deployment-structure.xml as shown below. The reason being, JBoss As 7.1 binds the logging module by default for the applications deployed in it. Hence it is required to explicitly exclude it in the deployments and it is also required to exclude for every sub deployment of your application, like if an EAR deployment is composed of multiple JAR deployments and WAR deployments it has to be mentioned explicitly for each one of them.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
   <jboss-deployment-structure>

   <deployment>
     <exclusions>
       <module name="org.apache.log4j" />
     </exclusions>
   </deployment>
   <sub-deployment name="<war-deployment-name>.war">
    <exclusions>
       <module name="org.apache.log4j" />
    </exclusions>
  </sub-deployment>
  <sub-deployment name="<jar1-deployment-name>.jar">
    <exclusions>
       <module name="org.apache.log4j" />
    </exclusions>
 </sub-deployment>
<sub-deployment name="<jar2-deployment-name>.jar">
    <exclusions>
       <module name="org.apache.log4j" />
    </exclusions>
 </sub-deployment>
</jboss-deployment-structure>

Replace the <war-deployment-name>,<jar-1-deployment-name>,<jar2-deployment-name> with the corresponding actual deployment archive names. It took me some time after pondering over, to figure out that the explicit exclusion has to be done for each sub-deployment and as well the name has to match with the sub-deployment name defined in the application.xml/ or the name of the actual sub-deployment.

Comments