Include code source location in message for competing LoggerFactory impl

To make it easier to identify the source of the competing LoggerFactory
implementation, this commit updates the exception message to include
the code source location of the offending class.

Closes gh-1630
pull/2035/head
Andy Wilkinson 10 years ago
parent f7d1f968b9
commit e47435f1b1

@ -90,10 +90,16 @@ 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(LoggerContext.class, factory,
"LoggerFactory is not a Logback LoggerContext but "
+ "Logback is on the classpath. Either remove Logback "
+ "or the competing implementation (" + factory.getClass() + ")");
Assert.isInstanceOf(
LoggerContext.class,
factory,
String.format(
"LoggerFactory is not a Logback LoggerContext but Logback is on "
+ "the classpath. Either remove Logback or the competing "
+ "implementation (%s loaded from %s).",
factory.getClass(), factory.getClass().getProtectionDomain()
.getCodeSource().getLocation()));
LoggerContext context = (LoggerContext) factory;
context.stop();
context.reset();

Loading…
Cancel
Save