Don't catch Throwable in InternalLoggerFactory (#10866)
Motivation: We shouldnt catch Throwable in InternalLoggerFactory as this may hide OOME etc. Modifications: Only catch LinkageError and Exception Result: Fixes https://github.com/netty/netty/issues/10857
This commit is contained in:
parent
d6121a2ecb
commit
7843d4e2e5
@ -39,24 +39,66 @@ public abstract class InternalLoggerFactory {
|
|||||||
|
|
||||||
@SuppressWarnings("UnusedCatchParameter")
|
@SuppressWarnings("UnusedCatchParameter")
|
||||||
private static InternalLoggerFactory newDefaultFactory(String name) {
|
private static InternalLoggerFactory newDefaultFactory(String name) {
|
||||||
InternalLoggerFactory f;
|
InternalLoggerFactory f = useSlf4JLoggerFactory(name);
|
||||||
|
if (f != null) {
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
f = useLog4J2LoggerFactory(name);
|
||||||
|
if (f != null) {
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
f = useLog4JLoggerFactory(name);
|
||||||
|
if (f != null) {
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return useJdkLoggerFactory(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static InternalLoggerFactory useSlf4JLoggerFactory(String name) {
|
||||||
try {
|
try {
|
||||||
f = new Slf4JLoggerFactory(true);
|
InternalLoggerFactory f = new Slf4JLoggerFactory(true);
|
||||||
f.newInstance(name).debug("Using SLF4J as the default logging framework");
|
f.newInstance(name).debug("Using SLF4J as the default logging framework");
|
||||||
} catch (Throwable ignore1) {
|
return f;
|
||||||
|
} catch (LinkageError ignore) {
|
||||||
|
return null;
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
// We catch Exception and not ReflectiveOperationException as we still support java 6
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static InternalLoggerFactory useLog4J2LoggerFactory(String name) {
|
||||||
try {
|
try {
|
||||||
f = Log4J2LoggerFactory.INSTANCE;
|
InternalLoggerFactory f = Log4J2LoggerFactory.INSTANCE;
|
||||||
f.newInstance(name).debug("Using Log4J2 as the default logging framework");
|
f.newInstance(name).debug("Using Log4J2 as the default logging framework");
|
||||||
} catch (Throwable ignore2) {
|
return f;
|
||||||
|
} catch (LinkageError ignore) {
|
||||||
|
return null;
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
// We catch Exception and not ReflectiveOperationException as we still support java 6
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static InternalLoggerFactory useLog4JLoggerFactory(String name) {
|
||||||
try {
|
try {
|
||||||
f = Log4JLoggerFactory.INSTANCE;
|
InternalLoggerFactory f = Log4JLoggerFactory.INSTANCE;
|
||||||
f.newInstance(name).debug("Using Log4J as the default logging framework");
|
f.newInstance(name).debug("Using Log4J as the default logging framework");
|
||||||
} catch (Throwable ignore3) {
|
return f;
|
||||||
f = JdkLoggerFactory.INSTANCE;
|
} catch (LinkageError ignore) {
|
||||||
|
return null;
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
// We catch Exception and not ReflectiveOperationException as we still support java 6
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static InternalLoggerFactory useJdkLoggerFactory(String name) {
|
||||||
|
InternalLoggerFactory f = JdkLoggerFactory.INSTANCE;
|
||||||
f.newInstance(name).debug("Using java.util.logging as the default logging framework");
|
f.newInstance(name).debug("Using java.util.logging as the default logging framework");
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user