19-Log4j整合到Netty
Log4j整合到Netty
添加POM依赖
<dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.25</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.7.25</version> <scope>test</scope> </dependency>
在Resource下新建log4j.properties
log4j.rootLogger=DEBUG, stdout log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern = [%p]%C{1}-%m%n
测试
启动上一个案例的服务端测试
[DEBUG]Slf4JLogger-Using SLF4J as the default logging framework [DEBUG]Slf4JLogger--Dio.netty.eventLoopThreads: 16 [DEBUG]Slf4JLogger-Platform: Windows [DEBUG]Slf4JLogger--Dio.netty.noUnsafe: false [DEBUG]Slf4JLogger-Java version: 8 [DEBUG]Slf4JLogger-sun.misc.Unsafe.theUnsafe: available [DEBUG]Slf4JLogger-sun.misc.Unsafe.copyMemory: available [DEBUG]Slf4JLogger-java.nio.Buffer.address: available [DEBUG]Slf4JLogger-direct buffer constructor: available [DEBUG]Slf4JLogger-java.nio.Bits.unaligned: available, true [DEBUG]Slf4JLogger-jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 [DEBUG]Slf4JLogger-java.nio.DirectByteBuffer.<init>(long, int): available [DEBUG]Slf4JLogger-sun.misc.Unsafe: available [DEBUG]Slf4JLogger--Dio.netty.tmpdir: C:\Users\EXT~1.CAI\AppData\Local\Temp (java.io.tmpdir) [DEBUG]Slf4JLogger--Dio.netty.bitMode: 64 (sun.arch.data.model) [DEBUG]Slf4JLogger--Dio.netty.noPreferDirect: false [DEBUG]Slf4JLogger--Dio.netty.maxDirectMemory: 3760193536 bytes [DEBUG]Slf4JLogger--Dio.netty.uninitializedArrayAllocationThreshold: -1 [DEBUG]Slf4JLogger-java.nio.ByteBuffer.cleaner(): available [DEBUG]Slf4JLogger--Dio.netty.noKeySetOptimization: false [DEBUG]Slf4JLogger--Dio.netty.selectorAutoRebuildThreshold: 512 [DEBUG]Slf4JLogger-org.jctools-core.MpscChunkedArrayQueue: available [DEBUG]Slf4JLogger--Dio.netty.processId: 14236 (auto-detected) [DEBUG]Slf4JLogger--Djava.net.preferIPv4Stack: false [DEBUG]Slf4JLogger--Djava.net.preferIPv6Addresses: false [DEBUG]Slf4JLogger-Loopback interface: lo (Software Loopback Interface 1, 127.0.0.1) [DEBUG]Slf4JLogger-Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 [DEBUG]Slf4JLogger--Dio.netty.machineId: 00:50:56:ff:fe:c0:00:08 (auto-detected) [DEBUG]Slf4JLogger--Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 [DEBUG]Slf4JLogger--Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 [DEBUG]Slf4JLogger--Dio.netty.leakDetection.level: simple [DEBUG]Slf4JLogger--Dio.netty.leakDetection.targetRecords: 4 [DEBUG]Slf4JLogger--Dio.netty.allocator.numHeapArenas: 16 [DEBUG]Slf4JLogger--Dio.netty.allocator.numDirectArenas: 16 [DEBUG]Slf4JLogger--Dio.netty.allocator.pageSize: 8192 [DEBUG]Slf4JLogger--Dio.netty.allocator.maxOrder: 11 [DEBUG]Slf4JLogger--Dio.netty.allocator.chunkSize: 16777216 [DEBUG]Slf4JLogger--Dio.netty.allocator.tinyCacheSize: 512 [DEBUG]Slf4JLogger--Dio.netty.allocator.smallCacheSize: 256 [DEBUG]Slf4JLogger--Dio.netty.allocator.normalCacheSize: 64 [DEBUG]Slf4JLogger--Dio.netty.allocator.maxCachedBufferCapacity: 32768 [DEBUG]Slf4JLogger--Dio.netty.allocator.cacheTrimInterval: 8192 [DEBUG]Slf4JLogger--Dio.netty.allocator.useCacheForAllThreads: true [DEBUG]Slf4JLogger--Dio.netty.allocator.type: pooled [DEBUG]Slf4JLogger--Dio.netty.threadLocalDirectBufferSize: 65536 [DEBUG]Slf4JLogger--Dio.netty.maxThreadLocalCharBufferSize: 16384 [INFO]Slf4JLogger-[id: 0x7449a0c5] REGISTERED [INFO]Slf4JLogger-[id: 0x7449a0c5] BIND: /127.0.0.1:7000 server is ready ...... [INFO]Slf4JLogger-[id: 0x7449a0c5, L:/127.0.0.1:7000] ACTIVE
ok~