如何配置netty logger工厂以查看LoggingHandler的输出? [英] How to configure netty logger factory in order to see the output of LoggingHandler?
问题描述
我正在使用slf4j和logback进行日志记录,并且在我编写的应用程序开始时
I am using slf4j logging with logback and at the beginning of my app I wrote
InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
然后将新的LoggingHandler(InternalLogLevel.DEBUG)
实例添加到管道中.
不幸的是,它仍然没有记录任何内容,我正在调试中,而调试级别是问题所在,只是跳过了记录本身.
then I added to the pipeline a new LoggingHandler(InternalLogLevel.DEBUG)
instance.
Unfortunately, this still does not log anything, I was debugging into and the debug level is the problem, just skips the logging itself.
我应该如何设置才能使用此LoggingHandler
?
How should I setup to get working this LoggingHandler
?
推荐答案
我做了一个小例子,它确实有效-我将其放在要点在github 上.它使用logback作为slf4j的后端.应该注意的时刻是:
I have done a small example, that does work - I placed it on gist on github. It uses logback as the backend of the slf4j. The moments that should be paid attention to are:
-
InternalLoggerFactory.setDefaultFactory(Slf4JLoggerFactory.INSTANCE);
应该直接在程序的入口点执行.有时候,这个入口点"可能很难确定. - 正确配置slf4j后端.由于slf4j只是一个包装器,它根本不处理配置-它特定于log4j,logback或java.util.logging(或者可能是一些自定义后端-我已经大量使用了自定义的"java commons logging"配置器,因此真的可以使用任何东西)
-
即使没有LoggingHandler,您也应该从org.jboss.netty.channel.socket.nio.SelectorUtil(Netty版本3.6.0.Final)的静态初始化程序中看到两条调试消息:
InternalLoggerFactory.setDefaultFactory(Slf4JLoggerFactory.INSTANCE);
should be executed right on the entry point of your program. Sometimes this "entry point" may be very hard to determine.- Proper configuration of slf4j backend. Since slf4j is only a wrapper it does not deal with configuration at all - it is specific for log4j, logback or java.util.logging (or maybe some custom backend - I have worked heavily with the custom "java commons logging" configurator, so really anything really can be used)
Even without LoggingHandler you should see two debug messages from static initializer of org.jboss.netty.channel.socket.nio.SelectorUtil (with Netty version 3.6.0.Final):
11:54:00.959 [main] DEBUG o.j.n.c.socket.nio.SelectorUtil - Using select timeout of 500
11:54:00.962 [main] DEBUG o.j.n.c.socket.nio.SelectorUtil - Epoll-bug workaround enabled = false
这篇关于如何配置netty logger工厂以查看LoggingHandler的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!