我正在使用Netty(通过Ning异步HTTP library)通过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
答案 0 :(得分:17)
通过缩写的包名来判断,似乎我在这里使用slf4j / logback进行日志记录。 在这种情况下,只需在类路径中尝试包含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
答案 1 :(得分:4)
我知道一个旧问题的延迟发布,但我最近不得不关闭来自netty的烦人的重复INFO级别日志记录:
[main] INFO com.ning.http.client.providers.netty.NettyAsyncHttpProvider - Number of application's worked threads is 16
在我的情况下,我需要以编程方式禁用它。查看slf4j org.slf4j.impl.SimpleLogger(netty调用的logger外观)我发现了一种简单的方法来控制你自己的启动代码中所有SimpleLogger实例的默认slf4j日志级别:
System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "warn");
或仅对我感兴趣的记录器实例:
System.setProperty(SimpleLogger.LOG_KEY_PREFIX + "com.ning.http.client", "warn");
值可以是“trace”,“debug”,“info”,“warn”或“error”中的任何一个,默认值为“info”。