如何引导 log4j 输出,以便不同的日志级别发送到不同的附加程序?
是否可以将“debug”和“info”输出写入控制台,而“info”输出仅写入某个日志文件? 例如,给定以下日志记录:
LOG.debug(fileContent);
LOG.info(fileLength);
相应的 log4j.xml
是什么样子?
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);
What does a corresponding log4j.xml
look like?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
好的,我现在明白了:
谢谢您的帮助!
Ok, I've got it now:
Thanks for your help!
这绝对是可能的。 配置看起来像这样(不检查语法正确性):
所有调试和信息消息都发送到控制台附加程序。 信息消息发送至
otherAppender
。That is definitely possible. The configuration would look something like this (not checked for syntactic correctness):
All debug and info messages go to the
console
appender. Info messages go tootherAppender
.转到 此页面查看一些示例。
它就像向程序中添加两个不同的附加程序一样简单,一个附加程序用于您想要执行的每种类型的日志记录。
Go to this page for some examples.
It's as simple as adding two different appenders to your program, one appender for each type of logging you want to do.
通过 Eddie 的配置,我只能获得 MyClass 的“info”输出。 但我想要的是 MyClass 的“信息”输出转到文件,而 MyClass 的“调试”输出转到控制台。
With the configuration from Eddie I can only get the "info" output for MyClass. But what I would like to have is that the "info" output of MyClass goes to a file AND the "debug" output of MyClass goes to console.
按照 rwwilden 建议的操作,但删除这部分:
并在 otherAppender 下添加
。
Do as rwwilden suggested but remove this part:
And add
<param name="Threshold" value="INFO"/>
under the otherAppender.