3

I have an ear that has a war as a sub deployment. The ear file has a META-INF directory that has a jboss-ejb-client.xml file which just has a ejb-recievers element and a webscheduler.war. This war uses the commons-logging-api.jar. This application is deployed on jboss as 7.1.1.final. I want to use apache log4j for logging. So I added a jboss-deployment-structure.xml in the meta-inf directory of the ear

<jboss-deployment-structure>
<deployment>
    <!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
    <exclusions>
        <module name="org.apache.log4j" />
        <module name="org.log4j"/>  
                <module name="org.jboss.logging"/>   
    </exclusions>
</deployment>
<sub-deployment name="a.war">
    <exclusions>
        <module name="org.apache.log4j"/>
     <module name="org.log4j"/>  
        <module name="org.jboss.logging"/>
    </exclusions>
</sub-deployment>
</jboss-deployment-structure>

I have a commons-logging.properties file in the lib directory of the war that has the following in it,

    org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl

log4j.configuration=/usr/share/wth/jboss/jboss-as-7.1.1/standalone/configuration/log4j.xml

Also apart from a log4j-1.2.11.jar I do not have any other logging framework jars in the lib.(like SLF4j etc). As you can see the log4j.xml is in the directory described by the property above.

the problem is when I start jboss, some application log does get written into the log file described in the log4j.xml (say /a/b/c/srv.log) , but simultaneously logs are also getting written into the default srv.log inside the jboss log directly.(jboss/standalone/log/srv.log).

What am I missing for jboss to not use its own logging and use the log4j configuration that I have provided.

TYS
  • 195
  • 1
  • 5
  • 16
  • Hope this will help http://stackoverflow.com/questions/14182257/using-applications-log4j-configuration-under-jboss-7-1-1/14337990#14337990 – gYanI Mar 07 '13 at 06:37

1 Answers1

2

Your jboss-deployment-structure.xml should look like:

<jboss-deployment-structure>
  <deployment>
    <exclusions>
      <module name="org.apache.log4j"/>
      <module name="org.apache.commons.logging"/>
    </exclusions>
  </deploymen>
  <sub-deployment name="a.war">
    <exclusions>
      <module name="org.apache.log4j"/>
      <module name="org.apache.commons.logging"/>
    </exclusions>
  </sub-deployment>
 </jboss-deployment-structure>

and you should have your own jars included within your project lib directory. For example:

EAR
|-- META-INF
|   |-- jboss-deployment-structure.xml
|   `-- MANIFEST.MF
|-- lib
|   |-- log4j.jar
|   `-- commons.logging.jar
`-- a.war

Make sure that you are deploying with the flag -Dorg.jboss.as.logging.per-deployment=false, otherwise the logging may not work.

Example:

$ cd $JBOSS_HOME/bin
$ ./standalone.sh -Dorg.jboss.as.logging.per-deployment=false
jyore
  • 4,715
  • 2
  • 21
  • 26
  • If you are not using ACL, then just remove all the module exclusions of ACL and the JAR in the examples above. – jyore Mar 06 '13 at 23:12
  • Thanks for your suggestions.I do not want to use ACL bundled inside jboss. So I added the exclusion org.apache.commons.logging in the deployment descriptor. The per-deployment flag as I know is now not looked at in jboss 7.1.1.final. However I have still added it. The problem is only some of the application log is going into my custom log.So it seems that the log4j configuration is being picked up.But the logs written by struts and hibernate libraries (inside my war) etc are all going into the jboss log directory for some reason. Some log – TYS Mar 07 '13 at 00:15
  • Only some log statements when jboss starts are written to my custom log file. These logs statements are coming from one of my classes in the war. – TYS Mar 07 '13 at 00:16
  • 1
    Just to clarify, the `org.jboss.as.logging.per-deployment` system property is not used in JBoss AS 7.1.1.Final. The Hibernate libraries inside you're WAR probably aren't being used so they're loaded by a different CL which is why they aren't logged to your application log file. – James R. Perkins Mar 07 '13 at 17:52
  • 1
    James I think is correct... to use your own hibernate, you should exclude the jboss hibernate jars and include your own as you did with the logging jars via the jboss-deployment-structure.xml – jyore Mar 08 '13 at 03:19