use of org.springframework.boot.logging.LogFile 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");
}
use of org.springframework.boot.logging.LogFile in project spring-boot by spring-projects.
the class LogbackLoggingSystemTests method initializeShouldSetSystemProperty.
@Test
public void initializeShouldSetSystemProperty() throws Exception {
// gh-5491
this.loggingSystem.beforeInitialize();
this.logger.info("Hidden");
LogFile logFile = getLogFile(tmpDir() + "/example.log", null, false);
this.loggingSystem.initialize(this.initializationContext, "classpath:logback-nondefault.xml", logFile);
assertThat(System.getProperty("LOG_FILE")).endsWith("example.log");
}
use of org.springframework.boot.logging.LogFile in project spring-boot by spring-projects.
the class LoggingApplicationListener method initialize.
/**
* Initialize the logging system according to preferences expressed through the
* {@link Environment} and the classpath.
* @param environment the environment
* @param classLoader the classloader
*/
protected void initialize(ConfigurableEnvironment environment, ClassLoader classLoader) {
new LoggingSystemProperties(environment).apply();
LogFile logFile = LogFile.get(environment);
if (logFile != null) {
logFile.applyToSystemProperties();
}
initializeEarlyLoggingLevel(environment);
initializeSystem(environment, this.loggingSystem, logFile);
initializeFinalLoggingLevels(environment, this.loggingSystem);
registerShutdownHookIfNecessary(environment, this.loggingSystem);
}
Aggregations