Java:更改外部库 Maven 依赖项的日志级别

标签 java maven logging browsermob-proxy browsermob

我正在使用 maven 将外部依赖项 BrowserMob Proxy 导入到我的 Java 项目中:

			    <dependency>
				<groupId>net.lightbody.bmp</groupId>
				<artifactId>browsermob-core-littleproxy</artifactId>
				<version>2.1.0-beta-3</version>
			</dependency>

但是,当我使用这个库时,它在 DEBUG 级别的输出中非常冗长,以至于我几乎看不到我的程序在做什么。我怎样才能减少这个库产生的输出量? 我基本上看到了很多这样的东西:

[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ClientToProxyConnection] (AWAITING_INITIAL) [id: 0x22000b92, L:/10.140.210.128:54435 - R:/10.140.210.128:54470]: Wrote: DefaultHttpContent(data: SimpleLeakAwareByteBuf(SlicedAbstractByteBuf(ridx: 0, widx: 1024, cap: 1024/1024, unwrapped: UnpooledUnsafeNoCleanerDirectByteBuf(ridx: 1024, widx: 1024, cap: 1024))), decoderResult: success)
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ClientToProxyConnection] (AWAITING_INITIAL) [id: 0x22000b92, L:/10.140.210.128:54435 - R:/10.140.210.128:54470]: Not closing server connection on middle chunk for /renderer/vapi/current/v.js
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ClientToProxyConnection] (AWAITING_INITIAL) [id: 0x22000b92, L:/10.140.210.128:54435 - R:/10.140.210.128:54470]: Not closing client connection on middle chunk for /renderer/vapi/current/v.js
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ProxyToServerConnection] (AWAITING_CHUNK) [id: 0x1e7ff722, L:/10.140.210.128:54478 - R:usweb.dotomi.com/23.215.104.50:80]: Reading: DefaultHttpContent(data: SlicedAbstractByteBuf(ridx: 0, widx: 1024, cap: 1024/1024, unwrapped: UnpooledUnsafeNoCleanerDirectByteBuf(ridx: 1024, widx: 1024, cap: 1024)), decoderResult: success)
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ClientToProxyConnection] (AWAITING_INITIAL) [id: 0x22000b92, L:/10.140.210.128:54435 - R:/10.140.210.128:54470]: Retaining reference counted message
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ClientToProxyConnection] (AWAITING_INITIAL) [id: 0x22000b92, L:/10.140.210.128:54435 - R:/10.140.210.128:54470]: Writing: DefaultHttpContent(data: SlicedAbstractByteBuf(ridx: 0, widx: 1024, cap: 1024/1024, unwrapped: UnpooledUnsafeNoCleanerDirectByteBuf(ridx: 1024, widx: 1024, cap: 1024)), decoderResult: success)
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ClientToProxyConnection] (AWAITING_INITIAL) [id: 0x22000b92, L:/10.140.210.128:54435 - R:/10.140.210.128:54470]: Wrote: DefaultHttpContent(data: SlicedAbstractByteBuf(ridx: 0, widx: 1024, cap: 1024/1024, unwrapped: UnpooledUnsafeNoCleanerDirectByteBuf(ridx: 1024, widx: 1024, cap: 1024)), decoderResult: success)
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ClientToProxyConnection] (AWAITING_INITIAL) [id: 0x22000b92, L:/10.140.210.128:54435 - R:/10.140.210.128:54470]: Not closing server connection on middle chunk for /renderer/vapi/current/v.js
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ClientToProxyConnection] (AWAITING_INITIAL) [id: 0x22000b92, L:/10.140.210.128:54435 - R:/10.140.210.128:54470]: Not closing client connection on middle chunk for /renderer/vapi/current/v.js
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ProxyToServerConnection] (AWAITING_CHUNK) [id: 0x1e7ff722, L:/10.140.210.128:54478 - R:usweb.dotomi.com/23.215.104.50:80]: Reading: DefaultHttpContent(data: SlicedAbstractByteBuf(ridx: 0, widx: 1024, cap: 1024/1024, unwrapped: UnpooledUnsafeNoCleanerDirectByteBuf(ridx: 1024, widx: 1024, cap: 1024)), decoderResult: success)
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ClientToProxyConnection] (AWAITING_INITIAL) [id: 0x22000b92, L:/10.140.210.128:54435 - R:/10.140.210.128:54470]: Retaining reference counted message
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ClientToProxyConnection] (AWAITING_INITIAL) [id: 0x22000b92, L:/10.140.210.128:54435 - R:/10.140.210.128:54470]: Writing: DefaultHttpContent(data: SlicedAbstractByteBuf(ridx: 0, widx: 1024, cap: 1024/1024, unwrapped: UnpooledUnsafeNoCleanerDirectByteBuf(ridx: 1024, widx: 1024, cap: 1024)), decoderResult: success)
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ClientToProxyConnection] (AWAITING_INITIAL) [id: 0x22000b92, L:/10.140.210.128:54435 - R:/10.140.210.128:54470]: Wrote: DefaultHttpContent(data: SlicedAbstractByteBuf(ridx: 0, widx: 1024, cap: 1024/1024, unwrapped: UnpooledUnsafeNoCleanerDirectByteBuf(ridx: 1024, widx: 1024, cap: 1024)), decoderResult: success)
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ClientToProxyConnection] (AWAITING_INITIAL) [id: 0x22000b92, L:/10.140.210.128:54435 - R:/10.140.210.128:54470]: Not closing server connection on middle chunk for /renderer/vapi/current/v.js
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ClientToProxyConnection] (AWAITING_INITIAL) [id: 0x22000b92, L:/10.140.210.128:54435 - R:/10.140.210.128:54470]: Not closing client connection on middle chunk for /renderer/vapi/current/v.js
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ProxyToServerConnection] (AWAITING_CHUNK) [id: 0x1e7ff722, L:/10.140.210.128:54478 - R:usweb.dotomi.com/23.215.104.50:80]: Reading: DefaultHttpContent(data: SlicedAbstractByteBuf(ridx: 0, widx: 1024, cap: 1024/1024, unwrapped: UnpooledUnsafeNoCleanerDirectByteBuf(ridx: 1024, widx: 1024, cap: 1024)), decoderResult: success)
[2018-04-09 15:04:40] [DEBUG] [LittleProxy-0-ProxyToServerWorker-1] [o.l.p.i.ClientToProxyConnection] (AWAITING_INITIAL) [id: 0x22000b92, L:/10.140.210.128:54435 - R:/10.140.210.128:54470]: Retaining reference counted message

最佳答案

Here's a similar question with a solution.那会满足您的需求吗?它的工作原理是将 System.out 定向到“/dev/null”或文件 (logFile),然后在完成后将其设置回控制台。

这里是问题的代码片段以供引用:

PrintStream stdout = System.out;
System.setOut(new PrintStream(logFile));

// ...

System.setOut(stdout);  

关于Java:更改外部库 Maven 依赖项的日志级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49741241/

相关文章:

java - 在 Bundle 测试中设置 EditText 不起作用

java - Antlr 3.4.0 生成的解析器的输入不匹配,而不是在解释器中

java - 莫尔斯电码到英语/英语到莫尔斯电码转换器

unit-testing - 如果我@Ignore JUnit4 中的测试类,@BeforeClass 是否仍然运行?

tomcat - Tomcat 启动后 Log4j 不工作

java - 如果映射的键已知,如何提取映射中列表的大小?

java - Maven 从曾祖 parent 而不是我们的 parent 依赖管理中采购依赖版本

maven - 如何在 Maven 程序集插件中停止 INFO 级别的登录

node.js - Ubuntu 哪里可以看到 console.logs

scala - 更改 phantom embedded Cassandra 的日志级别