java - Logback 配置忽略了我的日志记录级别

标签 java logging logback

我在我的项目中越来越频繁地记录日志,而且我无法抑制我不想要的日志语句。

我正在使用通过添加到我的 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 生成的 stub 代码。当我使用该 stub 代码调用 Web 服务时,会生成这些记录器。我没有编写这些日志记录语句,所以我只能假设它们来自 CXF。

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

最佳答案

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

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

关于java - Logback 配置忽略了我的日志记录级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23923156/

相关文章:

java - 为什么 "paragraph reference component"显示空图 block (Geometrixx 示例)?

带有 Spring 参数的 Java Akka Actors

java - 如何正确地将 jars 组织到 Eclipse 中的一个文件夹中?

node.js - 如果将文件可写流传递给 Node.js 中的控制台构造函数,是异步写入吗?

logging - 拦截来自 Ant 的 Commons 日志记录

java - Java Swing 组件中老挝文本的显示问题

php - 如何在 Codeigniter 中更改日志文件扩展名

hadoop - 如何更改MR作业的日志级别

eclipse - 编写 XSD 架构来验证任何 XML 文件是否有效

java - 配置 Play Framework 日志文件在生产中的位置