|
|
|
@ -39,10 +39,10 @@ import org.springframework.boot.ApplicationPid; |
|
|
|
import org.springframework.boot.SpringApplication; |
|
|
|
import org.springframework.boot.SpringApplication; |
|
|
|
import org.springframework.boot.context.event.ApplicationStartedEvent; |
|
|
|
import org.springframework.boot.context.event.ApplicationStartedEvent; |
|
|
|
import org.springframework.boot.logging.java.JavaLoggingSystem; |
|
|
|
import org.springframework.boot.logging.java.JavaLoggingSystem; |
|
|
|
import org.springframework.boot.testutil.EnvironmentTestUtils; |
|
|
|
|
|
|
|
import org.springframework.boot.testutil.OutputCapture; |
|
|
|
import org.springframework.boot.testutil.OutputCapture; |
|
|
|
import org.springframework.context.event.ContextClosedEvent; |
|
|
|
import org.springframework.context.event.ContextClosedEvent; |
|
|
|
import org.springframework.context.support.GenericApplicationContext; |
|
|
|
import org.springframework.context.support.GenericApplicationContext; |
|
|
|
|
|
|
|
import org.springframework.test.context.support.TestPropertySourceUtils; |
|
|
|
import org.springframework.test.util.ReflectionTestUtils; |
|
|
|
import org.springframework.test.util.ReflectionTestUtils; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
@ -128,8 +128,8 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void overrideConfigLocation() { |
|
|
|
public void overrideConfigLocation() { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.config: classpath:logback-nondefault.xml"); |
|
|
|
"logging.config=classpath:logback-nondefault.xml"); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.logger.info("Hello world"); |
|
|
|
this.logger.info("Hello world"); |
|
|
|
@ -140,8 +140,8 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void overrideConfigDoesNotExist() throws Exception { |
|
|
|
public void overrideConfigDoesNotExist() throws Exception { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.config: doesnotexist.xml"); |
|
|
|
"logging.config=doesnotexist.xml"); |
|
|
|
this.thrown.expect(IllegalStateException.class); |
|
|
|
this.thrown.expect(IllegalStateException.class); |
|
|
|
this.outputCapture.expect(containsString( |
|
|
|
this.outputCapture.expect(containsString( |
|
|
|
"Logging system failed to initialize using configuration from 'doesnotexist.xml'")); |
|
|
|
"Logging system failed to initialize using configuration from 'doesnotexist.xml'")); |
|
|
|
@ -151,7 +151,7 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void azureDefaultLoggingConfigDoesNotCauseAFailure() throws Exception { |
|
|
|
public void azureDefaultLoggingConfigDoesNotCauseAFailure() throws Exception { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.config: -Djava.util.logging.config.file=\"d:\\home\\site\\wwwroot\\bin\\apache-tomcat-7.0.52\\conf\\logging.properties\""); |
|
|
|
"logging.config: -Djava.util.logging.config.file=\"d:\\home\\site\\wwwroot\\bin\\apache-tomcat-7.0.52\\conf\\logging.properties\""); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
@ -163,8 +163,8 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void overrideConfigBroken() throws Exception { |
|
|
|
public void overrideConfigBroken() throws Exception { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.config: classpath:logback-broken.xml"); |
|
|
|
"logging.config=classpath:logback-broken.xml"); |
|
|
|
this.thrown.expect(IllegalStateException.class); |
|
|
|
this.thrown.expect(IllegalStateException.class); |
|
|
|
this.outputCapture.expect(containsString( |
|
|
|
this.outputCapture.expect(containsString( |
|
|
|
"Logging system failed to initialize using configuration from 'classpath:logback-broken.xml'")); |
|
|
|
"Logging system failed to initialize using configuration from 'classpath:logback-broken.xml'")); |
|
|
|
@ -175,9 +175,9 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void addLogFileProperty() { |
|
|
|
public void addLogFileProperty() { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.config: classpath:logback-nondefault.xml", |
|
|
|
"logging.config=classpath:logback-nondefault.xml", |
|
|
|
"logging.file: target/foo.log"); |
|
|
|
"logging.file=target/foo.log"); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class); |
|
|
|
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class); |
|
|
|
@ -189,7 +189,8 @@ public class LoggingApplicationListenerTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void addLogFilePropertyWithDefault() { |
|
|
|
public void addLogFilePropertyWithDefault() { |
|
|
|
assertThat(new File("target/foo.log").exists()).isFalse(); |
|
|
|
assertThat(new File("target/foo.log").exists()).isFalse(); |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, "logging.file: target/foo.log"); |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
|
|
|
|
"logging.file=target/foo.log"); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class); |
|
|
|
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class); |
|
|
|
@ -199,9 +200,9 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void addLogPathProperty() { |
|
|
|
public void addLogPathProperty() { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.config: classpath:logback-nondefault.xml", |
|
|
|
"logging.config=classpath:logback-nondefault.xml", |
|
|
|
"logging.path: target/foo/"); |
|
|
|
"logging.path=target/foo/"); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class); |
|
|
|
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class); |
|
|
|
@ -212,7 +213,7 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void parseDebugArg() throws Exception { |
|
|
|
public void parseDebugArg() throws Exception { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, "debug"); |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "debug"); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.logger.debug("testatdebug"); |
|
|
|
this.logger.debug("testatdebug"); |
|
|
|
@ -223,7 +224,7 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void parseTraceArg() throws Exception { |
|
|
|
public void parseTraceArg() throws Exception { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, "trace"); |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "trace"); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.logger.debug("testatdebug"); |
|
|
|
this.logger.debug("testatdebug"); |
|
|
|
@ -243,7 +244,8 @@ public class LoggingApplicationListenerTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void disableDebugTraceArg(String... environment) { |
|
|
|
private void disableDebugTraceArg(String... environment) { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, environment); |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
|
|
|
|
environment); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.logger.debug("testatdebug"); |
|
|
|
this.logger.debug("testatdebug"); |
|
|
|
@ -254,7 +256,7 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void parseLevels() throws Exception { |
|
|
|
public void parseLevels() throws Exception { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.level.org.springframework.boot=TRACE"); |
|
|
|
"logging.level.org.springframework.boot=TRACE"); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
@ -266,7 +268,7 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void parseLevelsCaseInsensitive() throws Exception { |
|
|
|
public void parseLevelsCaseInsensitive() throws Exception { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.level.org.springframework.boot=TrAcE"); |
|
|
|
"logging.level.org.springframework.boot=TrAcE"); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
@ -278,8 +280,8 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void parseLevelsWithPlaceholder() throws Exception { |
|
|
|
public void parseLevelsWithPlaceholder() throws Exception { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, "foo=TRACE", |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.level.org.springframework.boot=${foo}"); |
|
|
|
"foo=TRACE", "logging.level.org.springframework.boot=${foo}"); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.logger.debug("testatdebug"); |
|
|
|
this.logger.debug("testatdebug"); |
|
|
|
@ -290,7 +292,7 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void parseLevelsFails() throws Exception { |
|
|
|
public void parseLevelsFails() throws Exception { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.level.org.springframework.boot=GARBAGE"); |
|
|
|
"logging.level.org.springframework.boot=GARBAGE"); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
@ -301,7 +303,7 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void parseLevelsNone() throws Exception { |
|
|
|
public void parseLevelsNone() throws Exception { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.level.org.springframework.boot=OFF"); |
|
|
|
"logging.level.org.springframework.boot=OFF"); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
@ -313,7 +315,7 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void parseLevelsMapsFalseToOff() throws Exception { |
|
|
|
public void parseLevelsMapsFalseToOff() throws Exception { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.level.org.springframework.boot=false"); |
|
|
|
"logging.level.org.springframework.boot=false"); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
@ -326,7 +328,7 @@ public class LoggingApplicationListenerTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void parseArgsDisabled() throws Exception { |
|
|
|
public void parseArgsDisabled() throws Exception { |
|
|
|
this.initializer.setParseArgs(false); |
|
|
|
this.initializer.setParseArgs(false); |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, "debug"); |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "debug"); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.logger.debug("testatdebug"); |
|
|
|
this.logger.debug("testatdebug"); |
|
|
|
@ -365,8 +367,8 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void overrideExceptionConversionWord() throws Exception { |
|
|
|
public void overrideExceptionConversionWord() throws Exception { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.exceptionConversionWord:%rEx"); |
|
|
|
"logging.exceptionConversionWord=%rEx"); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.outputCapture.expect(containsString("Hello world")); |
|
|
|
this.outputCapture.expect(containsString("Hello world")); |
|
|
|
@ -392,8 +394,8 @@ public class LoggingApplicationListenerTests { |
|
|
|
TestLoggingApplicationListener listener = new TestLoggingApplicationListener(); |
|
|
|
TestLoggingApplicationListener listener = new TestLoggingApplicationListener(); |
|
|
|
System.setProperty(LoggingSystem.class.getName(), |
|
|
|
System.setProperty(LoggingSystem.class.getName(), |
|
|
|
TestShutdownHandlerLoggingSystem.class.getName()); |
|
|
|
TestShutdownHandlerLoggingSystem.class.getName()); |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.register_shutdown_hook:true"); |
|
|
|
"logging.register_shutdown_hook=true"); |
|
|
|
listener.onApplicationEvent( |
|
|
|
listener.onApplicationEvent( |
|
|
|
new ApplicationStartedEvent(new SpringApplication(), NO_ARGS)); |
|
|
|
new ApplicationStartedEvent(new SpringApplication(), NO_ARGS)); |
|
|
|
listener.initialize(this.context.getEnvironment(), this.context.getClassLoader()); |
|
|
|
listener.initialize(this.context.getEnvironment(), this.context.getClassLoader()); |
|
|
|
@ -436,7 +438,7 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void systemPropertiesAreSetForLoggingConfiguration() { |
|
|
|
public void systemPropertiesAreSetForLoggingConfiguration() { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.exception-conversion-word=conversion", "logging.file=target/log", |
|
|
|
"logging.exception-conversion-word=conversion", "logging.file=target/log", |
|
|
|
"logging.path=path", "logging.pattern.console=console", |
|
|
|
"logging.path=path", "logging.pattern.console=console", |
|
|
|
"logging.pattern.file=file", "logging.pattern.level=level"); |
|
|
|
"logging.pattern.file=file", "logging.pattern.level=level"); |
|
|
|
@ -454,7 +456,7 @@ public class LoggingApplicationListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void logFilePropertiesCanReferenceSystemProperties() { |
|
|
|
public void logFilePropertiesCanReferenceSystemProperties() { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, |
|
|
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, |
|
|
|
"logging.file=target/${PID}.log"); |
|
|
|
"logging.file=target/${PID}.log"); |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.initializer.initialize(this.context.getEnvironment(), |
|
|
|
this.context.getClassLoader()); |
|
|
|
this.context.getClassLoader()); |
|
|
|
|