log4j/log4cxx :记录器和附加器之间独占的 1 对 1 关系

发布于 2024-08-28 10:18:56 字数 506 浏览 5 评论 0原文

使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ら栖息 2024-09-04 10:18:56

为此,您可以使用以下配置:

<logger name="TRACER" additivity="false">
    <level value="Debug" />
    <appender-ref ref="DebugAppender" />
</logger>

名称以 TRACER 开头的所有记录器都将记录到附加程序 DebugAppender。有关详细信息,请查看此处此处

Additivity="false" 意味着发送到此记录器的消息不会向上传播记录器层次结构,因此它不会向根记录器打印任何内容。

You use the following piece of configuration for this:

<logger name="TRACER" additivity="false">
    <level value="Debug" />
    <appender-ref ref="DebugAppender" />
</logger>

All loggers with a name that starts with TRACER will log to the appender DebugAppender. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文