Commit aee42fcc authored by Dave Syer's avatar Dave Syer

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
parent de82557b
...@@ -77,7 +77,11 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem { ...@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment