【问题标题】:How to disable log4j debug-logging for http-api of com.spotify.docker-client如何为 com.spotify.docker-client 的 http-api 禁用 log4j 调试日志
【发布时间】:2018-10-04 06:56:24
【问题描述】:

在 Java8 中使用 log4j 1.2.17 和 com.spotify.docker-client 6.1.1。如果我在 DEBUG 中设置 log4j 根日志级别,那么 docker 客户端的 http-api 会在日志中写入许多消息,例如

09:42:50,624 DEBUG jersey-client-async-executor-0 headers:onResponseReceived:113 - http-outgoing-13 << HTTP/1.1 200 OK
09:42:50,624 DEBUG jersey-client-async-executor-0 headers:onResponseReceived:116 - http-outgoing-13 << Api-Version: 1.37
09:42:50,624 DEBUG jersey-client-async-executor-0 headers:onResponseReceived:116 - http-outgoing-13 << Docker-Experimental: false
09:42:50,624 DEBUG jersey-client-async-executor-0 headers:onResponseReceived:116 - http-outgoing-13 << Ostype: linux
09:42:50,624 DEBUG jersey-client-async-executor-0 headers:onResponseReceived:116 - http-outgoing-13 << Server: Docker/18.03.1-ce (linux)
09:42:50,624 DEBUG jersey-client-async-executor-0 headers:onResponseReceived:116 - http-outgoing-13 << Date: Thu, 04 Oct 2018 06:42:50 GMT
09:42:50,624 DEBUG jersey-client-async-executor-0 headers:onResponseReceived:116 - http-outgoing-13 << Content-Type: text/plain; charset=utf-8
09:42:50,624 DEBUG jersey-client-async-executor-0 headers:onResponseReceived:116 - http-outgoing-13 << Transfer-Encoding: chunked

我不明白如何禁用它。我所有的尝试:

log4j.rootLogger=DEBUG, stdout
log4j.logger.jersey-client-async-executor-0=INFO
log4j.logger.com.sun.jersey=INFO
log4j.logger.com.spotify=INFO

这并不能阻止它。如何禁用 jersey-client-async-executor-0 的 DEBUG-loggin ?谢谢。

【问题讨论】:

  • 你把我弄糊涂了。您正在设置调试器,但您不想要它。然后把它注释掉......也许只是改写你的问题是什么以及你在寻找什么。
  • 我想看到来自类的调试消息,但对于一些不感兴趣的类(对我来说),比如 jersey-client,我不想看到它。

标签: java-8 log4j spotify-docker-client


【解决方案1】:

您将日志级别设置为 Debug,然后您在记录器上登录 jersey-client,因此它也被设置为调试级别。

要么将你的 rootlogger 设置为不同的级别,要么不将 jersey-client 添加到 logger。

【讨论】:

    【解决方案2】:

    log4j 中,所有用户定义的记录器都从其父级继承,并且所有记录器都是rootLogger. 的直接或间接子级

    为了阻止您的记录器从父级继承,请将其添加到您的代码中:

    log4j.additivity.jersey-client-async-executor-0=false
    

    这将允许您为该特定组件定义您想要的任何日志级别,并且只定义您定义的那个。所以你只需要:

    log4j.rootLogger=DEBUG, stdout
    log4j.logger.jersey-client-async-executor-0=INFO, stdout
    log4j.additivity.jersey-client-async-executor-0=false
    

    请注意,您还可以为您定义的每个记录器设置不同的附加程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 2019-11-02
      • 2012-04-24
      • 1970-01-01
      • 1970-01-01
      • 2015-03-14
      相关资源
      最近更新 更多