Search in sources :

Example 1 with LogFile

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");
}
Also used : LogFile(org.springframework.boot.logging.LogFile) LoggingInitializationContext(org.springframework.boot.logging.LoggingInitializationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) LogFile(org.springframework.boot.logging.LogFile) File(java.io.File) Test(org.junit.Test)

Example 2 with LogFile

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");
}
Also used : LogFile(org.springframework.boot.logging.LogFile) Test(org.junit.Test)

Example 3 with LogFile

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);
}
Also used : LogFile(org.springframework.boot.logging.LogFile) LoggingSystemProperties(org.springframework.boot.logging.LoggingSystemProperties)

Aggregations

LogFile (org.springframework.boot.logging.LogFile)3 Test (org.junit.Test)2 File (java.io.File)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 LoggingInitializationContext (org.springframework.boot.logging.LoggingInitializationContext)1 LoggingSystemProperties (org.springframework.boot.logging.LoggingSystemProperties)1 MockEnvironment (org.springframework.mock.env.MockEnvironment)1