0%

java | netty 关闭多输出的 logger

我在使用 netty 的时候,总是会自己输出很多 logger

我使用 netty 总是会输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
21:28:11.881 [main] DEBUG io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework
21:28:11.893 [main] DEBUG io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 16
21:28:11.929 [main] DEBUG io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024
21:28:11.929 [main] DEBUG io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096
21:28:11.955 [main] DEBUG io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false
21:28:11.955 [main] DEBUG io.netty.util.internal.PlatformDependent0 - Java version: 8
21:28:11.957 [main] DEBUG io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available
21:28:11.957 [main] DEBUG io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available
21:28:11.957 [main] DEBUG io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.storeFence: available
21:28:11.958 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available
21:28:11.958 [main] DEBUG io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available
21:28:11.960 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true
21:28:11.960 [main] DEBUG io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9
21:28:11.960 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.<init>(long, int): available
21:28:11.960 [main] DEBUG io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available
21:28:11.960 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: /var/folders/_w/m_m732l53hb_bzmctrr1p3940000gn/T (java.io.tmpdir)
21:28:11.960 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model)
21:28:11.961 [main] DEBUG io.netty.util.internal.PlatformDependent - Platform: MacOS
21:28:11.962 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1908932608 bytes
21:28:11.962 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1
21:28:11.963 [main] DEBUG io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available
21:28:11.963 [main] DEBUG io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false
21:28:11.964 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false
21:28:11.964 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512
21:28:11.972 [main] DEBUG io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available
21:28:12.014 [main] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.processId: 63580 (auto-detected)
21:28:12.016 [main] DEBUG io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false
21:28:12.016 [main] DEBUG io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false
21:28:12.018 [main] DEBUG io.netty.util.NetUtilInitializations - Loopback interface: lo0 (lo0, 0:0:0:0:0:0:0:1%lo0)
21:28:12.019 [main] DEBUG io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file /proc/sys/net/core/somaxconn. Default: 128
21:28:12.022 [main] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:ff:c2:ff:fe:46:b4:f4 (auto-detected)
21:28:12.032 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple
21:28:12.032 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4
21:28:12.058 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 16
21:28:12.058 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 16
21:28:12.058 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192
21:28:12.058 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 9
21:28:12.058 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 4194304
21:28:12.058 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256
21:28:12.058 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64
21:28:12.058 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768
21:28:12.058 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192
21:28:12.059 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimIntervalMillis: 0
21:28:12.059 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: false
21:28:12.059 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedByteBuffersPerChunk: 1023
21:28:12.067 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled
21:28:12.067 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0
21:28:12.067 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384
21:28:12.150 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096
21:28:12.150 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
21:28:12.150 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.chunkSize: 32
21:28:12.150 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.blocking: false

根据 How to turn off Netty library debug output using SLF4J programmatically? 的用法,只需要

1
2
3
4
5
6
7
8
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.Logger;


LoggerContext loggerContext = (LoggerContext)LoggerFactory.getILoggerFactory();
Logger rootLogger = loggerContext.getLogger("io.netty");
rootLogger.setLevel(ch.qos.logback.classic.Level.OFF);

这样就关闭了。

请我喝杯咖啡吧~