Netty internal logger issue

試著忘記壹切 提交于 2019-12-12 05:37:32

问题


I am using Netty 4.1.6. Is it possible to set netty using log4j2 as internal logger? Eclipse prompt me that the following statement is depreciated.

InternalLoggerFactory.setDefaultFactory(new Log4J2LoggerFactory());

Would you tell me how to do so?


回答1:


Thanks Ferrybig for the tip.

I am elaborating on how to do this on log4j2.

Before you do the Netty server bootstrap, insert this line above.

InternalLoggerFactory.setDefaultFactory(Log4J2LoggerFactory.INSTANCE);
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.group(bossGroup, workerGroup)
 .channel(NioServerSocketChannel.class)
 .handler(new LoggingHandler(LogLevel.INFO))
 .childHandler(new ...

Then on the log4j2.xml have the loggers and the corresponding Appenders.

<Logger name="io.netty" level="INFO" additivity="false">
   <AppenderRef ref="nettyTrace"/>
</Logger>


来源:https://stackoverflow.com/questions/40255418/netty-internal-logger-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!