use of org.springframework.boot.logging.LoggingInitializationContext in project spring-boot by spring-projects.
the class LoggingApplicationListener method initializeSystem.
private void initializeSystem(ConfigurableEnvironment environment, LoggingSystem system, LogFile logFile) {
LoggingInitializationContext initializationContext = new LoggingInitializationContext(environment);
String logConfig = environment.getProperty(CONFIG_PROPERTY);
if (ignoreLogConfig(logConfig)) {
system.initialize(initializationContext, null, logFile);
} else {
try {
ResourceUtils.getURL(logConfig).openStream().close();
system.initialize(initializationContext, logConfig, logFile);
} catch (Exception ex) {
// NOTE: We can't use the logger here to report the problem
System.err.println("Logging system failed to initialize " + "using configuration from '" + logConfig + "'");
ex.printStackTrace(System.err);
throw new IllegalStateException(ex);
}
}
}
use of org.springframework.boot.logging.LoggingInitializationContext in project spring-boot by spring-projects.
the class SpringBootJoranConfiguratorTests method setup.
@Before
public void setup() {
this.environment = new MockEnvironment();
this.initializationContext = new LoggingInitializationContext(this.environment);
this.configurator = new SpringBootJoranConfigurator(this.initializationContext);
StaticLoggerBinder binder = StaticLoggerBinder.getSingleton();
this.context = (LoggerContext) binder.getLoggerFactory();
this.logger = this.context.getLogger(getClass());
}
use of org.springframework.boot.logging.LoggingInitializationContext in project spring-boot by spring-projects.
the class LogbackLoggingSystemTests method setup.
@Before
public void setup() {
this.loggingSystem.cleanUp();
this.logger = new SLF4JLogFactory().getInstance(getClass().getName());
this.environment = new MockEnvironment();
this.initializationContext = new LoggingInitializationContext(this.environment);
}
use of org.springframework.boot.logging.LoggingInitializationContext in project spring-boot by spring-projects.
the class LogbackLoggingSystemTests method testConsolePatternProperty.
@Test
public void testConsolePatternProperty() {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("logging.pattern.console", "%logger %msg");
LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(environment);
this.loggingSystem.initialize(loggingInitializationContext, null, null);
this.logger.info("Hello world");
String output = this.output.toString().trim();
assertThat(getLineWithText(output, "Hello world")).doesNotContain("INFO");
}
use of org.springframework.boot.logging.LoggingInitializationContext in project spring-boot by spring-projects.
the class LogbackLoggingSystemTests method testFilePatternProperty.
@Test
public void testFilePatternProperty() throws Exception {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("logging.pattern.file", "%logger %msg");
LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(environment);
File file = new File(tmpDir(), "logback-test.log");
LogFile logFile = getLogFile(file.getPath(), null);
this.loggingSystem.initialize(loggingInitializationContext, null, logFile);
this.logger.info("Hello world");
String output = this.output.toString().trim();
assertThat(getLineWithText(output, "Hello world")).contains("INFO");
assertThat(getLineWithText(file, "Hello world")).doesNotContain("INFO");
}
Aggregations