Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable a custom log4j with Jboss AS 7.1

I tried several options. But anything didn't work for me. Previously I used the same log4j.xml (simple common config) with Tomcat 6,7 and I could able to control the root logging and the application logging with updating the log4j.xml. When I deploy the same project with JBoss AS 7.1, It only gives me INFO level logging and my log4j.xml doesn't work at all. Sometime this can be fixed by updating some configuration files inside the JBoss server, but I like to know if there a portable way to do it or something similar. If this is bug or something with JBoss AS 7.1 I like to know about a quick fix anyway. I haven't worked with JBoss before.

Thanks!

like image 481
sura2k Avatar asked Oct 22 '22 07:10

sura2k


1 Answers

I had this problem and solved it by following method:
use your own log4j jar instead of one that provided by jboss. Do it by excluding jboss org.apache.log4j jar module from your application (exclude it in jboss-deployment-structure.xml) and add your own log4j jar file in lib folder of the .ear package. Now put log4j.xml in the root folder of your module.
By this method you have full control on log4j (like standalone applications).
let me know if you need more help.

Sample jboss-deployment-structure.xml for excluding log4j.jar:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
    <exclusions>
        <module name="org.apache.log4j" slot="main"/>
    </exclusions>
</deployment>

 <sub-deployment name="MyEjb.jar">
    <exclusions>
        <module name="org.apache.log4j"/>
    </exclusions>
</sub-deployment>

like image 183
hyda Avatar answered Oct 24 '22 11:10

hyda