多个具有登录条件的root记录器 [英] multiple root loggers with logback conditionals

查看:85
本文介绍了多个具有登录条件的root记录器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引用:登录的配置

我的配置可以包含 ...at most one <root> element...

但是后来在同一个文档中,当讨论条件时,我看到了:

but then later in the same doc, when discussing conditionals, I see this:

<configuration debug="true">
  <if condition='property("HOSTNAME").contains("torino")'>
    <then>
      <appender name="CON" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
          <pattern>%d %-5level %logger{35} - %msg %n</pattern>
        </encoder>
      </appender>
      <root> <------ root logger #1
        <appender-ref ref="CON" />
      </root>
    </then>
  </if>

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>${randomOutputDir}/conditional.log</file>
    <encoder>
      <pattern>%d %-5level %logger{35} - %msg %n</pattern>
   </encoder>
  </appender>

  <root level="ERROR"> <------ root logger #2
     <appender-ref ref="FILE" />
  </root>
</configuration>

请注意,有两个<root>元素!我很困惑,因为我看不到任何<else>元素,并且即使主机名是"torino",我仍认为FILE appender和第二个root logger仍在起作用.

Notice there are TWO <root> elements! I'm very confused because I don't see any <else> elements and I would assume the FILE appender and the second root logger are still in play, even if the hostname was "torino".

这是一个有效的例子吗?为什么在一个<if><else>

How is this a valid example? Why are two <root> loggers allowed in this case when one is not within an <if> or an <else>

我想念什么?

推荐答案

免责声明:我是logback项目的维护者.

Disclaimer: I am the maintainer of the logback project.

这绝对值得在logback文档中进行说明.您能否在 http://jira.qos.ch 上提交错误报告?引用此StackOverflow条目就足够了.

This definitely deserves a clarification in the logback documentation. Can you please file a bug report at http://jira.qos.ch ? Referencing this StackOverflow entry should be enough.

对于哪个root记录器处于活动状态,假设条件为true,则它们都将处于活动状态.名为FILE和CON的两个附加程序都将附加到根记录器.该级别将设置为最后一个值集.请注意,条件中的根元素未设置级别.

As for which root logger is active, assuming the conditional is true, they will be both active. Both appenders named FILE and CON would be attached to the root logger. The level would be set to the last value set. Note that the root element within the conditional does not set a level.

这篇关于多个具有登录条件的root记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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