Logging Configuration in JBoss 7.1

JBoss 7.1 has the log4j module built in. When developing, the project can just include the logging API lib (like log4j) in the project classpath, so that the project compiles. When build, the log4j.jar/log4j.xml/log4j.properties does not need to be packed in the deployment archive (ear, or war). It would be ignored by JBoss 7 even you include them in the archive.

 

The configuration file for the standalone server is "C:\jboss-as-7.1.1\standalone\configuration\standalone.xml".

 

To confiure the console output format and the server log file, just edit the section for logging.

 

<subsystem xmlns="urn:jboss:domain:logging:1.1">
            <console-handler name="CONSOLE">
                <level name="DEBUG"/>
                <formatter>
                    <pattern-formatter pattern="%d %-5p [%c] %m%n"/>
                </formatter>
            </console-handler>
            <periodic-rotating-file-handler name="FILE">
                <formatter>
                    <pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                </formatter>
                <file relative-to="jboss.server.log.dir" path="server.log"/>
                <suffix value=".yyyy-MM-dd"/>
                <append value="true"/>
            </periodic-rotating-file-handler>
            <logger category="javax">
                <level name="INFO"/>
            </logger>
            <logger category="javax.enterprise">
                <level name="INFO"/>
            </logger>
            <logger category="javax.faces">
                <level name="INFO"/>
            </logger>
            <logger category="org.jboss">
                <level name="INFO"/>
            </logger>
            <logger category="org.hibernate">
                <level name="INFO"/>
            </logger>
            <logger category="com.sun">
                <level name="WARN"/>
            </logger>
            <logger category="com.arjuna">
                <level name="WARN"/>
            </logger>
            <logger category="org.apache">
                <level name="ERROR"/>
            </logger>
            <logger category="org.apache.tomcat.util.modeler">
                <level name="WARN"/>
            </logger>
            <logger category="sun.rmi">
                <level name="WARN"/>
            </logger>
            <logger category="jacorb">
                <level name="WARN"/>
            </logger>
            <logger category="jacorb.config">
                <level name="ERROR"/>
            </logger>
            <root-logger>
                <level name="DEBUG"/>
                <handlers>
                    <handler name="CONSOLE"/>
                    <handler name="FILE"/>
                </handlers>
            </root-logger>
        </subsystem>

 

In the above example, the two root loggers has logging level set to "DEBUG", in order to remove some bloat output from javax, jboss, apache etc, it sets those categories to logging level "INFO" or even "ERROR". Note that "DEBUG/INFO/ERROR" etc might be case sensitive and lower case not working.

 

With this configuration, the console output looks like this:

2012-08-22 13:11:57,306 DEBUG [test.jxee.action.AsyncEJBTestBean] testCallAndGetResult... 1345597917306
2012-08-22 13:11:57,321 DEBUG [test.jxee.action.AsyncEJBTestBean] AsyncEJB not finished yet, pause 1 second...
2012-08-22 13:11:57,321 DEBUG [test.jxee.ejb.AsyncEJB] >>> AsyncEJB inited: test.jxee.ejb.AsyncEJB@11e36af
2012-08-22 13:11:57,321 DEBUG [test.jxee.ejb.AsyncEJB] >>> callAndGetResult() started: 1345597917321
2012-08-22 13:11:58,321 DEBUG [test.jxee.action.AsyncEJBTestBean] AsyncEJB not finished yet, pause 1 second...
2012-08-22 13:11:59,321 DEBUG [test.jxee.action.AsyncEJBTestBean] AsyncEJB not finished yet, pause 1 second...
2012-08-22 13:12:00,321 DEBUG [test.jxee.action.AsyncEJBTestBean] AsyncEJB not finished yet, pause 1 second...
2012-08-22 13:12:01,321 DEBUG [test.jxee.action.AsyncEJBTestBean] AsyncEJB not finished yet, pause 1 second...
2012-08-22 13:12:02,321 DEBUG [test.jxee.ejb.AsyncEJB] >>> callAndGetResult() about to send result: 1345597922321
2012-08-22 13:12:02,321 DEBUG [test.jxee.action.AsyncEJBTestBean] testCallAndGetResult...done 1345597922321

 

Problem: What if i want to use my own log4j configuration?

 

This is rare use case, simple answer is why and what the point to use your own logging configuration?

 

Here's how if you really want to do it. Since JBoss 7.1 already has the log4j module installed, if you want to use your own logging implementation, you need to tell JBoss to unload its log4j. This can be done by providing a conf file called "META-INF/jboss-deployment-structure.xml". It needs to be at a "META-INF" folder, which is located at the root of your deployment archive, ie, ear or war.

 

Here's an example of this conf file to prevent JBoss 7 from loading it default log4j module:

 

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <!-- to prevent the server from automatically adding some modules-->
        <exclusions>
            <module name="org.apache.log4j" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值