How to enable a custom log4j with Jboss AS 7.1

半城伤御伤魂 提交于 2019-12-07 06:10:34

问题


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!


回答1:


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>



来源:https://stackoverflow.com/questions/17136035/how-to-enable-a-custom-log4j-with-jboss-as-7-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!