简体   繁体   English

如何打开Netty中的纯文本日志记录?

[英]How do i turn on plain text logging in netty?

Is there a way to turn on plain text logging in netty output ? 有没有办法在netty输出中打开纯文本日志记录?

How do i turn on plain text logging in netty ? 如何打开netty中的纯文本日志记录?

Thank you 谢谢

add a LoggingHandler to your pipeline: LoggingHandler添加到管道中:

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

By default this Handler logs to console but you can define a different LoggererFactory . 默认情况下,此Handler记录到控制台,但是您可以定义其他LoggererFactory

From the JavaDoc: 从JavaDoc:

Creates an InternalLogger or changes the default factory implementation. 创建一个InternalLogger或更改默认的工厂实现。 This factory allows you to choose what logging framework Netty should use. 该工厂允许您选择Netty应该使用的日志框架。 The default factory is Slf4JLoggerFactory. 默认工厂为Slf4JLoggerFactory。 If SLF4J is not available, Log4JLoggerFactory is used. 如果SLF4J不可用,则使用Log4JLoggerFactory。 If Log4J is not available, JdkLoggerFactory is used. 如果Log4J不可用,则使用JdkLoggerFactory。 You can change it to your preferred logging framework before other Netty classes are loaded: InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory()); 您可以在加载其他Netty类之前将其更改为首选的日志记录框架: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. 因此,应尽早调用setDefaultFactory(InternalLoggerFactory),并且不应多次调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM