如何引导log4j输出,以便将不同的日志级别分配给不同的附加程序? [英] How can I direct log4j output so that different log levels go to different appenders?

查看:65
本文介绍了如何引导log4j输出,以便将不同的日志级别分配给不同的附加程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能将调试"和信息"输出写入控制台,而信息"输出仅写入某些日志文件吗?例如,给出以下日志记录:

Is it possible to have "debug" and "info" output written to the console while the "info" output is only written to some log file? For example, given this logging:

LOG.debug(fileContent);
LOG.info(fileLength);

对应的log4j.xml是什么样的?

推荐答案

好,我现在知道了:

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        ...
    </appender>

    <appender name="otherAppender"
              class="org.apache.log4j.FileAppender FileAppender">
       <param name="Threshold" value="INFO"/>
        ...
    </appender>

    <root>
        <priority     value="debug" />
        <appender-ref ref="console" />
        <appender-ref ref="otherAppender" />
    </root>
</log4j:configuration>

感谢您的帮助!

这篇关于如何引导log4j输出,以便将不同的日志级别分配给不同的附加程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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