How to turn off Netty library debug output?

自古美人都是妖i 提交于 2020-01-12 13:55:39

问题


I am using Netty (via the Ning async HTTP library) to retrieve documents via HTTP. This produces a huge amount of debug output the console, as listed below for a single document request.

Anyone know how to turn this off? I really don't need to see this output.

I'm calling from Scala, if that makes any difference.

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:


judging by the abbreviated package names seems to me slf4j/logback is being used for logging here. in that case just try including a logback.xml configuration file in your classpath. something along the lines of

<?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>

the above xml would cause anything under com.ning.http.client (and downwards) to omit only warnings and worse to the output, which will be streamed to system.out. anything else will ommit INFO+ you can find more information on configuring logback here: http://logback.qos.ch/manual/configuration.html




回答2:


Late posting for an old question I know but I recently had to turn off annoying repetitive INFO level logging coming from netty:

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

In my case I needed to disable it programmatically. Looking into slf4j org.slf4j.impl.SimpleLogger (the logger facade called by netty) I discovered an easy way to control the default slf4j log level for all SimpleLogger instances in your own startup code:

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

or for just the logger instance I was interested in:

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

The value can be any of "trace", "debug", "info", "warn", or "error" with the default being "info".



来源:https://stackoverflow.com/questions/11852689/how-to-turn-off-netty-library-debug-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!