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
This commit is contained in:
Dave Syer 2013-12-24 09:54:35 +00:00
parent de82557bd8
commit aee42fcc18
1 changed files with 5 additions and 1 deletions

View File

@ -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 {