|
|
@ -57,6 +57,7 @@ import ch.qos.logback.core.status.Status;
|
|
|
|
public class LogbackLoggingSystem extends Slf4JLoggingSystem {
|
|
|
|
public class LogbackLoggingSystem extends Slf4JLoggingSystem {
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<LogLevel, Level> LEVELS;
|
|
|
|
private static final Map<LogLevel, Level> LEVELS;
|
|
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
Map<LogLevel, Level> levels = new HashMap<LogLevel, Level>();
|
|
|
|
Map<LogLevel, Level> levels = new HashMap<LogLevel, Level>();
|
|
|
|
levels.put(LogLevel.TRACE, Level.TRACE);
|
|
|
|
levels.put(LogLevel.TRACE, Level.TRACE);
|
|
|
@ -85,8 +86,8 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected String[] getStandardConfigLocations() {
|
|
|
|
protected String[] getStandardConfigLocations() {
|
|
|
|
return new String[] { "logback-test.groovy", "logback-test.xml",
|
|
|
|
return new String[] { "logback-test.groovy", "logback-test.xml", "logback.groovy",
|
|
|
|
"logback.groovy", "logback.xml" };
|
|
|
|
"logback.xml" };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -109,6 +110,9 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
|
|
|
|
LoggerContext context = getLoggerContext();
|
|
|
|
LoggerContext context = getLoggerContext();
|
|
|
|
stopAndReset(context);
|
|
|
|
stopAndReset(context);
|
|
|
|
LogbackConfigurator configurator = new LogbackConfigurator(context);
|
|
|
|
LogbackConfigurator configurator = new LogbackConfigurator(context);
|
|
|
|
|
|
|
|
context.putProperty("LOG_LEVEL_PATTERN",
|
|
|
|
|
|
|
|
initializationContext.getEnvironment().resolvePlaceholders(
|
|
|
|
|
|
|
|
"${logging.pattern.level:${LOG_LEVEL_PATTERN:%5p}}"));
|
|
|
|
new DefaultLogbackConfiguration(initializationContext, logFile)
|
|
|
|
new DefaultLogbackConfiguration(initializationContext, logFile)
|
|
|
|
.apply(configurator);
|
|
|
|
.apply(configurator);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -127,8 +131,8 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
|
|
|
|
ResourceUtils.getURL(location));
|
|
|
|
ResourceUtils.getURL(location));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
catch (Exception ex) {
|
|
|
|
throw new IllegalStateException("Could not initialize Logback logging from "
|
|
|
|
throw new IllegalStateException(
|
|
|
|
+ location, ex);
|
|
|
|
"Could not initialize Logback logging from " + location, ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Status> statuses = loggerContext.getStatusManager().getCopyOfStatusList();
|
|
|
|
List<Status> statuses = loggerContext.getStatusManager().getCopyOfStatusList();
|
|
|
|
StringBuilder errors = new StringBuilder();
|
|
|
|
StringBuilder errors = new StringBuilder();
|
|
|
@ -139,8 +143,8 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (errors.length() > 0) {
|
|
|
|
if (errors.length() > 0) {
|
|
|
|
throw new IllegalStateException("Logback configuration error "
|
|
|
|
throw new IllegalStateException(
|
|
|
|
+ "detected: \n" + errors);
|
|
|
|
"Logback configuration error " + "detected: \n" + errors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -197,14 +201,15 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
|
|
|
|
|
|
|
|
|
|
|
|
private ch.qos.logback.classic.Logger getLogger(String name) {
|
|
|
|
private ch.qos.logback.classic.Logger getLogger(String name) {
|
|
|
|
LoggerContext factory = getLoggerContext();
|
|
|
|
LoggerContext factory = getLoggerContext();
|
|
|
|
return factory.getLogger(StringUtils.isEmpty(name) ? Logger.ROOT_LOGGER_NAME
|
|
|
|
return factory
|
|
|
|
: name);
|
|
|
|
.getLogger(StringUtils.isEmpty(name) ? Logger.ROOT_LOGGER_NAME : name);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private LoggerContext getLoggerContext() {
|
|
|
|
private LoggerContext getLoggerContext() {
|
|
|
|
ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory();
|
|
|
|
ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory();
|
|
|
|
Assert.isInstanceOf(LoggerContext.class, factory, String.format(
|
|
|
|
Assert.isInstanceOf(LoggerContext.class, factory,
|
|
|
|
|
|
|
|
String.format(
|
|
|
|
"LoggerFactory is not a Logback LoggerContext but Logback is on "
|
|
|
|
"LoggerFactory is not a Logback LoggerContext but Logback is on "
|
|
|
|
+ "the classpath. Either remove Logback or the competing "
|
|
|
|
+ "the classpath. Either remove Logback or the competing "
|
|
|
|
+ "implementation (%s loaded from %s). If you are using "
|
|
|
|
+ "implementation (%s loaded from %s). If you are using "
|
|
|
|