【问题标题】:Logback config is ignoring my logging levelLogback 配置忽略了我的日志记录级别
【发布时间】:2014-07-18 08:35:03
【问题描述】:

我在我的项目中获得了持续性的日志记录,并且在抑制我不想要的日志记录语句时遇到了麻烦。

我正在使用通过添加到我的 POM 中安装的 Logback。

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.0.13</version>
</dependency>

我的日志总是以这三行开头:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

谷歌搜索表明这是 Eclipse 问题,而不是 Logback 配置问题,但我将其包括在内,以防我的谷歌搜索误导了我。

这是我的 logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</Pattern>
    </layout>
  </appender>

  <logger name="com.my.project" level="TRACE"/>
  <logger name="o.a.cxf" level="INFO"/>
  <logger name="o.a.c" level="INFO"/>

  <root level="debug">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

这是我的日志摘录

[INFO] 17:41:53.095 DEBUG o.a.c.t.h.HttpsURLConnectionFactory - The SSL_DH_anon_WITH_DES_CBC_SHA cipher suite is excluded by the filter.
[INFO] 17:41:53.095 DEBUG o.a.c.t.h.HttpsURLConnectionFactory - The SSL_RSA_EXPORT_WITH_RC4_40_MD5 cipher suite is included by the filter.
[INFO] 17:41:53.095 DEBUG o.a.c.t.h.HttpsURLConnectionFactory - The SSL_DH_anon_EXPORT_WITH_RC4_40_MD5 cipher suite is excluded by the filter.
[INFO] 17:41:53.096 DEBUG o.a.c.t.h.HttpsURLConnectionFactory - The SSL_RSA_EXPORT_WITH_DES40_CBC_SHA cipher suite is included by the filter.
[INFO] 17:41:53.096 DEBUG o.a.c.t.h.HttpsURLConnectionFactory - The SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA cipher suite is included by the filter.
[INFO] 17:41:53.096 DEBUG o.a.c.t.h.HttpsURLConnectionFactory - The SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA cipher suite is included by the filter.
[INFO] 17:41:53.096 DEBUG o.a.c.t.h.HttpsURLConnectionFactory - The SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA cipher suite is excluded by the filter.
[INFO] 17:41:53.097 DEBUG o.a.c.t.h.HttpsURLConnectionFactory - The TLS_KRB5_WITH_RC4_128_SHA cipher suite is included by the filter.
[INFO] 17:41:53.103 DEBUG o.a.c.t.h.HttpsURLConnectionFactory - The TLS_KRB5_WITH_RC4_128_MD5 cipher suite is included by the filter.
[INFO] 17:41:53.103 DEBUG o.a.c.t.h.HttpsURLConnectionFactory - The TLS_KRB5_WITH_3DES_EDE_CBC_SHA cipher suite is included by the filter.
[INFO] 17:41:53.103 DEBUG o.a.c.t.h.HttpsURLConnectionFactory - The TLS_KRB5_WITH_3DES_EDE_CBC_MD5 cipher suite is included by the filter.
[INFO] 17:41:53.104 DEBUG o.a.c.t.h.HttpsURLConnectionFactory - The TLS_KRB5_WITH_DES_CBC_SHA cipher suite is included by the filter.
[INFO] 17:41:53.104 DEBUG o.a.c.t.h.HttpsURLConnectionFactory - The TLS_KRB5_WITH_DES_CBC_MD5 cipher suite is included by the filter.
[INFO] 17:41:53.104 DEBUG o.a.c.t.h.HttpsURLConnectionFactory - The TLS_KRB5_EXPORT_WITH_RC4_40_SHA cipher suite is included by the filter.
[INFO] 17:41:53.104 DEBUG o.a.c.t.h.HttpsURLConnectionFactory - The TLS_KRB5_EXPORT_WITH_RC4_40_MD5 cipher suite is included by the filter.

我已经通过修改 appender 中的模式验证了我的 logback.xml 文件正在被读取。这些变化正在得到尊重。但我希望将“o.a.c”的记录器设置为 INFO 会抑制这些 DEBUG 消息。我假设 [INFO] 也来自 Eclipse,而后面的 DEBUG 是实际的记录器级别。

更新

这些记录器由 Apache CXF 记录。我的项目中有一个依赖项,它具有使用 CXF 生成的存根代码。当我使用该存根代码调用 Web 服务时,会生成这些记录器。这些日志语句不是我写的,所以我只能假设它们来自 CXF。

另外,我在使用 Log4j 时看不到这些记录器。我正在尝试学习 Logback,因为我被分配评估它作为团队可能的升级。

【问题讨论】:

  • 何时/何地记录?你是如何启动你的项目的?最值得注意的是,这是一个众所周知的 m2e 问题,最常出现在 JUnit 中,并且计划在 Luna 中进行修复。
  • 我已更新问题以包含该信息。但是,如果 XML 配置文件设置正确,那么在何处/如何创建日志语句真的很重要吗?我的印象是,如果我为记录器设置日志记录级别,则无论在哪里调用它都应该被禁止。

标签: java logging logback


【解决方案1】:

虽然它在日志消息中显示o.a.c.t.h.HttpsURLConnectionFactory,但记录器名称实际上不是o.a.c.t.h.HttpsURLConnectionFactoryo.a.c... 只是全名的缩写。

我认为你应该在logback.xml 中使用org.apache.cxf 而不是o.a.co.a.cxf

【讨论】:

  • 做到了!我们有一些大型复杂项目,我可能不知道是什么导致了记录器。你知道有什么方法可以关闭缩写吗?
  • 在您的模式中,您使用的是%logger{36}。只需改用%logger
猜你喜欢
  • 2012-03-19
  • 2011-12-11
  • 2013-04-22
  • 1970-01-01
  • 2013-03-07
  • 1970-01-01
  • 1970-01-01
  • 2015-07-18
  • 2014-01-22
相关资源
最近更新 更多