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"); Assert.notNull(configLocation, "ConfigLocation must not be null");
String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(configLocation); String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(configLocation);
ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory(); 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; LoggerContext context = (LoggerContext) factory;
context.stop(); context.stop();
try { try {

Loading…
Cancel
Save