Add instanceof check and nice fat error message

If Logback and another SLF4J implementation are both on the classpath
it is possible for the LogbackLoggingSystem to fail to locate
a LoggerContext. Rather than a ClassCastException it is better to
make an assertion with an error message.

Fixes gh-162
pull/184/head
Dave Syer 11 years ago
parent de82557bd8
commit aee42fcc18

@ -77,7 +77,11 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem {
Assert.notNull(configLocation, "ConfigLocation must not be null");
String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(configLocation);
ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory();
Assert.isInstanceOf(ILoggerFactory.class, factory);
Assert.isInstanceOf(
LoggerContext.class,
factory,
"LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation ("
+ factory.getClass() + ")");
LoggerContext context = (LoggerContext) factory;
context.stop();
try {

Loading…
Cancel
Save