简体   繁体   中英

How do i turn on plain text logging in netty?

Is there a way to turn on plain text logging in netty output ?

How do i turn on plain text logging in netty ?

Thank you

add a LoggingHandler to your pipeline:

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

By default this Handler logs to console but you can define a different LoggererFactory .

From the 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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