From 93d2807ff0eb6d886a4da8fc52a97ea7bbc056b5 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 11 Jul 2018 10:19:37 +0100 Subject: [PATCH] Auto-detect Log4J2 for logging if on the class-path (#8109) Motivation: https://github.com/netty/netty/pull/5047 added Log4J2 support but missed to add code to try to auto-detect it. Modifications: Try to use Log4JLoggerFactory by default. Result: Fixes https://github.com/netty/netty/issues/8107. --- .../internal/logging/InternalLoggerFactory.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/io/netty/util/internal/logging/InternalLoggerFactory.java b/common/src/main/java/io/netty/util/internal/logging/InternalLoggerFactory.java index 9f85e3646b40..12c1b5a4477d 100644 --- a/common/src/main/java/io/netty/util/internal/logging/InternalLoggerFactory.java +++ b/common/src/main/java/io/netty/util/internal/logging/InternalLoggerFactory.java @@ -41,13 +41,18 @@ private static InternalLoggerFactory newDefaultFactory(String name) { try { f = new Slf4JLoggerFactory(true); f.newInstance(name).debug("Using SLF4J as the default logging framework"); - } catch (Throwable t1) { + } catch (Throwable ignore1) { try { f = Log4JLoggerFactory.INSTANCE; f.newInstance(name).debug("Using Log4J as the default logging framework"); - } catch (Throwable t2) { - f = JdkLoggerFactory.INSTANCE; - f.newInstance(name).debug("Using java.util.logging as the default logging framework"); + } catch (Throwable ignore2) { + try { + f = Log4J2LoggerFactory.INSTANCE; + f.newInstance(name).debug("Using Log4J2 as the default logging framework"); + } catch (Throwable ignore3) { + f = JdkLoggerFactory.INSTANCE; + f.newInstance(name).debug("Using java.util.logging as the default logging framework"); + } } } return f;