From aee42fcc18562d3c1e127b2b73d08e0e56dc9126 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 24 Dec 2013 09:54:35 +0000 Subject: [PATCH] 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 --- .../boot/logging/logback/LogbackLoggingSystem.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java b/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java index 5d402b261e6..26f555f2235 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java @@ -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 {