scala 如何关闭 Netty 库调试输出?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11852689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 04:25:31  来源:igfitidea点击:

How to turn off Netty library debug output?

javascalanettyerror-logging

提问by Jonathan Stray

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.

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

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.

我是从 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

回答by radai

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

从缩写的包名来看,在我看来 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>

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

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

回答by Craig

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

我知道一个老问题的迟到发布,但我最近不得不关闭来自 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:

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

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".

该值可以是“trace”、“debug”、“info”、“warn”或“error”中的任何一个,默认值为“info”。