仅排除Log4j Logger的一个级别 [英] Excluding only one level of Log4j Logger

查看:44
本文介绍了仅排除Log4j Logger的一个级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在还使用Axis2和Jetty Web服务器的应用程序中使用Log4j.

I'm using Log4j in a application in which I also use Axis2 and Jetty web server.

我将Log4J属性文件配置为在调试优先级时将这些类从日志中排除.但是当我这样做时,其他优先级消息也开始从主记录器中排除.

I configured the Log4J property file to exclude these classes from logging when in debug priority. But when I did this, the other priority messages also began to be excluded from the main logger.

有没有一种方法可以告诉Log4j我只想记录这些类中的INFO日志,同时记录我的类中的调试日志?

Is there a way that I can tell Log4j that I just want to log INFO logs from these classes while logging debug logs from my classes?

这就是我所做的:

#Jetty Server and Axis2
log4j.category.org.apache.axiom=DEBUG
log4j.additivity.org.apache.axiom=false
log4j.category.org.apache.axis2=DEBUG
log4j.additivity.org.apache.axis2=false

################# MAIN LOGGER #################
log4j.rootCategory=DEBUG, mainLogger

#File configuration

但是正如我所说的,此配置还排除了来自主记录器的INFO消息.

But as I said this configuration also exclude INFO messages from the main logger.

推荐答案

否,将根"级别设置为DEBUG,然后

No, set the Root level to DEBUG, and

log4j.category.org.apache.axiom=INFO
log4j.category.org.apache.axis2=INFO

此外,请勿将可加性设置为 false .

Also, do not set the additivity to false.

从头开始时,您可能想立即使用更现代的XML配置格式.在那里,看起来像这样:

When you're starting from scratch, you might want to use the more modern XML config format right away. There, it would look like this:

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

<appender name="FILE" class="org.apache.log4j.RollingFileAppender"> 
...
</appender> 

<category name="com.apache.axiom">
    <priority value="INFO" />
</category>

<root> 
    <priority value ="DEBUG" /> 
    <appender-ref ref="FILE" /> 
</root>

</log4j:configuration>

这篇关于仅排除Log4j Logger的一个级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆