|
|
|
|
@ -30,6 +30,7 @@ import ch.qos.logback.classic.Level;
@@ -30,6 +30,7 @@ import ch.qos.logback.classic.Level;
|
|
|
|
|
import ch.qos.logback.classic.LoggerContext; |
|
|
|
|
import ch.qos.logback.classic.joran.JoranConfigurator; |
|
|
|
|
import ch.qos.logback.classic.jul.LevelChangePropagator; |
|
|
|
|
import ch.qos.logback.classic.spi.TurboFilterList; |
|
|
|
|
import ch.qos.logback.classic.turbo.TurboFilter; |
|
|
|
|
import ch.qos.logback.core.joran.spi.JoranException; |
|
|
|
|
import ch.qos.logback.core.spi.FilterReply; |
|
|
|
|
@ -218,33 +219,37 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem implements BeanF
@@ -218,33 +219,37 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem implements BeanF
|
|
|
|
|
protected void loadDefaults(LoggingInitializationContext initializationContext, LogFile logFile) { |
|
|
|
|
LoggerContext context = getLoggerContext(); |
|
|
|
|
stopAndReset(context); |
|
|
|
|
boolean debug = Boolean.getBoolean("logback.debug"); |
|
|
|
|
if (debug) { |
|
|
|
|
StatusListenerConfigHelper.addOnConsoleListenerInstance(context, new OnConsoleStatusListener()); |
|
|
|
|
} |
|
|
|
|
Environment environment = initializationContext.getEnvironment(); |
|
|
|
|
// Apply system properties directly in case the same JVM runs multiple apps
|
|
|
|
|
new LogbackLoggingSystemProperties(environment, context::putProperty).apply(logFile); |
|
|
|
|
LogbackConfigurator configurator = debug ? new DebugLogbackConfigurator(context) |
|
|
|
|
: new LogbackConfigurator(context); |
|
|
|
|
new DefaultLogbackConfiguration(logFile).apply(configurator); |
|
|
|
|
context.setPackagingDataEnabled(true); |
|
|
|
|
withLoggingSuppressed(() -> { |
|
|
|
|
boolean debug = Boolean.getBoolean("logback.debug"); |
|
|
|
|
if (debug) { |
|
|
|
|
StatusListenerConfigHelper.addOnConsoleListenerInstance(context, new OnConsoleStatusListener()); |
|
|
|
|
} |
|
|
|
|
Environment environment = initializationContext.getEnvironment(); |
|
|
|
|
// Apply system properties directly in case the same JVM runs multiple apps
|
|
|
|
|
new LogbackLoggingSystemProperties(environment, context::putProperty).apply(logFile); |
|
|
|
|
LogbackConfigurator configurator = debug ? new DebugLogbackConfigurator(context) |
|
|
|
|
: new LogbackConfigurator(context); |
|
|
|
|
new DefaultLogbackConfiguration(logFile).apply(configurator); |
|
|
|
|
context.setPackagingDataEnabled(true); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void loadConfiguration(LoggingInitializationContext initializationContext, String location, |
|
|
|
|
LogFile logFile) { |
|
|
|
|
if (initializationContext != null) { |
|
|
|
|
applySystemProperties(initializationContext.getEnvironment(), logFile); |
|
|
|
|
} |
|
|
|
|
LoggerContext loggerContext = getLoggerContext(); |
|
|
|
|
stopAndReset(loggerContext); |
|
|
|
|
try { |
|
|
|
|
configureByResourceUrl(initializationContext, loggerContext, ResourceUtils.getURL(location)); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) { |
|
|
|
|
throw new IllegalStateException("Could not initialize Logback logging from " + location, ex); |
|
|
|
|
} |
|
|
|
|
withLoggingSuppressed(() -> { |
|
|
|
|
if (initializationContext != null) { |
|
|
|
|
applySystemProperties(initializationContext.getEnvironment(), logFile); |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
configureByResourceUrl(initializationContext, loggerContext, ResourceUtils.getURL(location)); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) { |
|
|
|
|
throw new IllegalStateException("Could not initialize Logback logging from " + location, ex); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
reportConfigurationErrorsIfNecessary(loggerContext); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -448,6 +453,17 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem implements BeanF
@@ -448,6 +453,17 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem implements BeanF
|
|
|
|
|
return contribution; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void withLoggingSuppressed(Runnable action) { |
|
|
|
|
TurboFilterList turboFilters = getLoggerContext().getTurboFilterList(); |
|
|
|
|
turboFilters.add(FILTER); |
|
|
|
|
try { |
|
|
|
|
action.run(); |
|
|
|
|
} |
|
|
|
|
finally { |
|
|
|
|
turboFilters.remove(FILTER); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* {@link LoggingSystemFactory} that returns {@link LogbackLoggingSystem} if possible. |
|
|
|
|
*/ |
|
|
|
|
|