如何关闭Netty库调试输出?

2022-09-02 20:38:53

我正在使用Netty(通过Ning异步HTTP)通过HTTP检索文档。这会在控制台中生成大量调试输出,如下所列的单个文档请求所示。

有人知道如何关闭它吗?我真的不需要看到这个输出。

我是从Scala打来的,如果这有什么区别的话。

15:07:14.273 [run-main] DEBUG c.n.h.c.p.n.NettyAsyncHttpProvider - 
Non cached request 
DefaultHttpRequest(chunked: false)
GET /api/search.json?q=foo HTTP/1.1
Host: www.documentcloud.org
Connection: keep-alive
Accept: */*
User-Agent: NING/1.0

using Channel 
[id: 0x2839ca40]

15:07:14.930 [New I/O client worker #1-1] DEBUG c.n.h.c.p.n.NettyAsyncHttpProvider - 

Request DefaultHttpRequest(chunked: false)
GET /api/search.json?q=foo HTTP/1.1
Host: www.documentcloud.org
Connection: keep-alive
Accept: */*
User-Agent: NING/1.0

Response DefaultHttpResponse(chunked: true)
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 10477
Connection: keep-alive
Vary: Accept-Encoding
Status: 200
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.13
ETag: "4f8f766d639dd84d014dfee3abb45de2"
X-Runtime: 611
Cache-Control: private, max-age=0, must-revalidate
Server: nginx/1.2.1 + Phusion Passenger 3.0.13 (mod_rails/mod_rack)

15:07:14.941 [New I/O client worker #1-1] DEBUG c.n.h.c.p.netty.NettyConnectionsPool - Adding uri: http://www.documentcloud.org:80 for channel [id: 0x2839ca40, /10.5.165.61:56133 => www.documentcloud.org/75.101.159.206:80]

15:07:16.921 [New I/O client worker #1-1] DEBUG c.n.h.c.p.n.NettyAsyncHttpProvider - Channel Closed: [id: 0x2839ca40, /10.5.165.61:56133 :> www.documentcloud.org/75.101.159.206:80] with attachment com.ning.http.client.providers.netty.NettyAsyncHttpProvider$DiscardEvent@63182c3d
15:08:13.924 [Timer-0] DEBUG c.n.h.c.p.netty.NettyConnectionsPool - Entry count for : http://www.documentcloud.org:80 : 0

答案 1

从缩写的软件包名称来看,在我看来,slf4j/logback在这里用于日志记录。在这种情况下,只需尝试在类路径中包含.xml回日志配置文件即可。类似的东西

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="STDOUT"/>
    </root>

    <logger name="com.ning.http.client" level="WARN"/>
</configuration>

上面的xml会导致com.ning.http.client(和向下)下的任何内容仅省略警告,并且输出更糟,输出将被流式传输到system.out。其他任何内容都会省略INFO+,您可以在此处找到有关配置日志的更多信息:http://logback.qos.ch/manual/configuration.html


答案 2

迟到的发布是一个我知道的老问题,但我最近不得不关闭来自netty的烦人的重复信息级别日志记录:

[main] INFO com.ning.http.client.providers.netty.NettyAsyncHttpProvider - Number of application's worked threads is 16

在我的情况下,我需要以编程方式禁用它。在查看 slf4j org.slf4j.impl.SimpleLogger(netty 调用的记录器外观)时,我发现了一种简单的方法,可以在您自己的启动代码中控制所有 SimpleLogger 实例的默认 slf4j 日志级别:

System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "warn");

或者只是我感兴趣的记录器实例:

System.setProperty(SimpleLogger.LOG_KEY_PREFIX + "com.ning.http.client", "warn");

该值可以是“跟踪”、“调试”、“信息”、“警告”或“错误”中的任何一个,默认值为“信息”。


推荐