java - 如何在 netty 中打开纯文本日志记录?

标签 java netty

有没有办法在 netty 输出中打开纯文本日志记录?

如何在 netty 中打开纯文本日志记录?

谢谢

最佳答案

LoggingHandler 添加到您的管道:

pipeline.addLast("logger", new LoggingHandler());

默认情况下,此处理程序记录到控制台,但您可以定义不同的LoggererFactory

来自 JavaDoc:

Creates an InternalLogger or changes the default factory implementation. This factory allows you to choose what logging framework Netty should use. The default factory is Slf4JLoggerFactory. If SLF4J is not available, Log4JLoggerFactory is used. If Log4J is not available, JdkLoggerFactory is used. You can change it to your preferred logging framework before other Netty classes are loaded: InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory());

Please note that the new default factory is effective only for the classes which were loaded after the default factory is changed. Therefore, setDefaultFactory(InternalLoggerFactory) should be called as early as possible and shouldn't be called more than once.

关于java - 如何在 netty 中打开纯文本日志记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30379007/

相关文章:

java - Netty 多个客户端,断开一个影响所有

tcp - 使用带 Netty 的 Apache Camel 负载平衡 TCP 流量导致事务失败

java - 如何在多次 repaint() 之后重新绘制 JComponent 一次?

java - 如何从点创建多边形 (Spatial4j)

java - 为什么当 ExecutorService 上的所有任务完成或取消时,awaitTermination 不能可靠地返回

java - java中的网络

java - 关闭 Netty UDP 服务器

java - ElasticSearch 占用 100% CPU

java - Redisson客户端Netty线程异常

java - 字符串到字节数组的转换