我心依然

统计

留言簿

个人收藏

阅读排行榜

评论排行榜

关于JBOSS与LOG4J,受益匪浅

        不同的服务器对于使用log4j是有些不同的,实际使用中主要是用tomcat和jboss两类,对于tomcat,它本身是没有配置log4j的,所以使用起来和常规的一样;而在jboss中它是本身配置了log4j的,所以有时候在看项目代码时,其整个项目并没有log4j的配置文件,而在一些类中仍然定义了Logger,例如static Logger log = org.apache.log4j.Logger.getLogger(UserDaoImple.class);,这就表明开发者打算使用jboss默认的log4j的配置,我们可以在jboss下的对应的log目录下的server.log中看到日志,jboss本身的log4j的配置是将debug,info级的日志写在server.log中,而像error等级别比较高的日志打印到控制台上,而写到server.log中的日志比较多,并不方便查看。于是我们想到使用自己的log4j配置写到某个具体的文件中(注意文件要先建立,才能忘里面写东西,log4j自己不能建立文件),但这里因为jboss有它自己的log4j配置,所以如果我们配置的log4j包含Console的Appender时,就会出错,错误类似于 ERROR: invalid console appender config detected, console stream is looping.
解决方法一是不用Console的Appender,或者改jboss的配置文件,在jboss-service.xml文件里,把
<mbean code="org.jboss.logging.Log4jService" name="jboss.system:type=Log4jService,service=Logging">
        <attribute name="ConfigurationURL">resource:log4j.xml</attribute>
        <attribute name="CatchSystemOut">false</attribute>
        <attribute name="Log4jQuietMode">true</attribute>
</mbean>。

我建议不用Console的Appender,当然这是对jboss3.2.x是这样,对于jboss4.0.x如果我们要用自己的log4j配置照上述改还是会有问题,会有类似于 log4j:ERROR A "org.jboss.logging.util.OnlyOnceErrorHandler" object is not assignable to a "org.apache.log4j.spi.ErrorHandler" variable 的异常,解决方法是把/server/default/jbossweb-tomcat55.sar/META-INF/jboss-service.xml 中的以下两个熟悉改成true
<attribute name="Java2ClassLoadingCompliance">true</attribute>
<attribute name="UseJBossWebLoader">true</attribute>

以上就是使用jboss服务器可能出现的问题,解决了这些再来使用log4j就比较简单了。

posted on 2006-11-28 22:54 Jerry Zhang 阅读(908) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: