【问题标题】:Logging Configuration Apache HttpClient 5 on WIldflyWIldfly 上的日志记录配置 Apache HttpClient 5
【发布时间】:2017-03-20 15:36:38
【问题描述】:

在 Wildfly 10.1 上关闭 apache httpclient 5 的调试日志记录时遇到问题。到目前为止,我已经完成了以下工作:

  1. standalone.xml,下

  2. logging.properties - 文档说明这仅在 wildfly 启动时生效,所以我没想到它会起作用:

    logger.org.apache.http.level=错误 logger.org.apache.http.wire.level=错误

  3. 添加了 java vm 参数:

    -org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog -Dorg.apache.commons.logging.simplelog.showdatetime=true -Dorg.apache.commons.logging.simplelog.log.org.apache.http=WARN -Dorg.apache.commons.logging.simplelog.log.org.apache.http.wire=WARN

  4. 通过代码尝试过:

    System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.defaultlog","error"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http","error"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire","error"); 客户端 = HttpClientBuilder.create().build();

没有运气,在任何这些上。

提前致谢。

【问题讨论】:

  • 能否举个日志输出的例子?
  • 11:08:21,910 INFO [stdout] (default task-2) 11:08:21.910 [default task-2] DEBUG org.apache.http.wire - http-outgoing-0 >> “内容长度:756[\r][\n]”11:08:21,911 INFO [stdout](默认任务 2)11:08:21.911 [默认任务 2] 调试 org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]" 11:08:21,994 INFO [stdout] (default task-2) 11:08:21.994 [default task-2]
  • 基本上得到了所有的http.wire DEBUG 行。
  • 部署中是否有日志记录配置文件 log4j 或 logging.properties 文件?

标签: apache logging httpclient wildfly


【解决方案1】:

来自我的项目:

要隐藏有关无效 cookie 的警告,请创建自定义配置

RequestConfig config = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
httpClient = HttpClients.custom().setDefaultRequestConfig(config).build();

或完全禁用日志记录

java.util.logging.Logger.getLogger("org.apache").setLevel(Level.OFF);

【讨论】:

  • 嗨 - 感谢您的输入 - 尝试过但没有成功。
【解决方案2】:

好的 - 想通了。我使用的是 SLF4J,但没有为 wildfly 配置它,请参阅 http://blog.anotheria.net/devops/enable-logback-in-jboss/
另外,我必须创建:META-INF/jboss-deployment-structure.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
  <deployment>
    <exclusions>
      <module name="org.apache.commons.logging" />
      <module name="org.apache.log4j" />
      <module name="org.jboss.logging" />
      <module name="org.jboss.logging.jul-to-slf4j-stub" />
      <module name="org.jboss.logmanager" />
      <module name="org.jboss.logmanager.log4j" />
      <module name="org.slf4j" />
      <module name="org.slf4j.impl" />
    </exclusions>
  </deployment>
</jboss-deployment-structure>

如果不这样做,我的日志文件中会出现双时间戳:

11:08:21,910 INFO [stdout] (default task-2) 11:08:21.910 [default task-2] DEBUG org.apache.http.wire

正确配置 SLF4J 后,修改 JVM 的 logging.properties 文件就像一个魅力:

/usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.91-2.b14.fc22.x86_64/lib/logging.properties
org.apache.http.level = SEVERE
org.apache.http.wire.level = SEVERE

请注意,在正确配置 SLF4J 之前,没有 apache http 客户端文档中列出的方法起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-29
    • 2020-05-23
    • 2018-05-05
    • 2014-07-18
    • 2014-02-28
    • 2015-07-20
    • 2011-03-15
    • 2015-05-28
    相关资源
    最近更新 更多