log4j/log4cxx :记录器和附加器之间独占的 1 对 1 关系
使用log4cxx的xml配置(与log4j的配置相同)。 我想让某个记录器专门输出到特定的附加程序(让它成为输出到该附加程序的唯一记录器)。
我发现可以将记录器绑定到特定的附加程序,如下所示:
<logger name="LoggerName">
<level value="info"/>
<appender-ref ref="AppenderName"/>
</logger>
但该记录器仍然输出到根附加程序,因为我在conf文件中有这个标准部分:
<root>
<priority value="DEBUG"/>
<appender-ref ref="OtherAppender"/>
</root>
如何从根记录器中排除该记录器? 换句话说,如何配置日志,以便除特定记录器之外的所有记录器都继承根记录器的附加程序?
Using the xml configuration of log4cxx (which is identical in configuration to log4j).
I want to have a certain logger output exclusively to a specific appender (have it the only logger which outputs to that appender).
I found that it's possible to bind a logger to a specific appender like this:
<logger name="LoggerName">
<level value="info"/>
<appender-ref ref="AppenderName"/>
</logger>
but it that logger still outputs to the root appender because I have this standard piece in the conf file:
<root>
<priority value="DEBUG"/>
<appender-ref ref="OtherAppender"/>
</root>
How can I exclude that logger from the root logger?
in other words, how do I configure the log such that all loggers inherit the appenders of the root logger except a specific logger?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,您可以使用以下配置:
名称以
TRACER
开头的所有记录器都将记录到附加程序DebugAppender
。有关详细信息,请查看此处或此处。Additivity="false" 意味着发送到此记录器的消息不会向上传播记录器层次结构,因此它不会向根记录器打印任何内容。
You use the following piece of configuration for this:
All loggers with a name that starts with
TRACER
will log to the appenderDebugAppender
. For more info, check here or here.Additivity="false" means messages to this logger will not propogate up the loggers hierarchy so it will not print anything to the root logger.