首页  

netty4日志     所属分类 netty 浏览量 1247
netty-all-4.0.16.Final.jar


io.netty.util.internal.logging

public abstract class InternalLoggerFactory {
    private static volatile InternalLoggerFactory defaultFactory;

    static {
        final String name = InternalLoggerFactory.class.getName();
        InternalLoggerFactory f;
        try {
            f = new Slf4JLoggerFactory(true);
            f.newInstance(name).debug("Using SLF4J as the default logging framework");
            defaultFactory = f;
        } catch (Throwable t1) {
            try {
                f = new Log4JLoggerFactory();
                f.newInstance(name).debug("Using Log4J as the default logging framework");
            } catch (Throwable t2) {
                f = new JdkLoggerFactory();
                f.newInstance(name).debug("Using java.util.logging as the default logging framework");
            }
        }

        defaultFactory = f;
    }
    
 
InternalLoggerFactory 日志框架检测

先检测 SLF4J,再检测Log4J,都没有的话,使用JDK Logging

slf4j 不存在 抛异常
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
	at dyyx.LogBackUtil.(LogBackUtil.java:8)
	at LogDemoTest.main(LogDemoTest.java:8)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	
	
SLF4J 支持日志占位符

logger.info("Hello,{}","netty4");

Log4J和JDK Logging 不支持 占位符

netty 日志做了适配  
io.netty.util.internal.logging.MessageFormatter

上一篇     下一篇
netty线程模型和零拷贝机制

netty组件

netty运行原理

UnsupportedClassVersionError处理

ServerBootstrap handler()和childHandler()的区别

性能及问题排查合集