Log4j2XmlTests Class — spring-boot Architecture
Architecture documentation for the Log4j2XmlTests class in Log4j2XmlTests.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4j2XmlTests.java lines 41–128
class Log4j2XmlTests {
protected @Nullable Configuration configuration;
@AfterEach
void stopConfiguration() {
if (this.configuration != null) {
this.configuration.stop();
}
}
@Test
void whenLogExceptionConversionWordIsNotConfiguredThenConsoleUsesDefault() {
assertThat(consolePattern()).contains("%xwEx");
}
@Test
void whenLogExceptionConversionWordIsSetThenConsoleUsesIt() {
withSystemProperty(LoggingSystemProperty.EXCEPTION_CONVERSION_WORD.getEnvironmentVariableName(), "custom",
() -> assertThat(consolePattern()).contains("custom"));
}
@Test
void whenLogLevelPatternIsNotConfiguredThenConsoleUsesDefault() {
assertThat(consolePattern()).contains("%5p");
}
@Test
void whenLogLevelPatternIsSetThenConsoleUsesIt() {
withSystemProperty(LoggingSystemProperty.LEVEL_PATTERN.getEnvironmentVariableName(), "custom",
() -> assertThat(consolePattern()).contains("custom"));
}
@Test
void whenLogLDateformatPatternIsNotConfiguredThenConsoleUsesDefault() {
assertThat(consolePattern()).contains("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
}
@Test
void whenLogDateformatPatternIsSetThenConsoleUsesIt() {
withSystemProperty(LoggingSystemProperty.DATEFORMAT_PATTERN.getEnvironmentVariableName(), "dd-MM-yyyy",
() -> assertThat(consolePattern()).contains("dd-MM-yyyy"));
}
protected void withSystemProperty(String name, String value, Runnable action) {
String previous = System.setProperty(name, value);
action.run();
if (previous == null) {
System.clearProperty(name);
}
else {
System.setProperty(name, previous);
}
}
private String consolePattern() {
prepareConfiguration();
assertThat(this.configuration).isNotNull();
return ((PatternLayout) this.configuration.getAppender("Console").getLayout()).getConversionPattern();
}
protected void prepareConfiguration() {
this.configuration = initializeConfiguration();
this.configuration.start();
}
protected Configuration initializeConfiguration() {
LoggerContext context = new LoggerContext("test");
Configuration configuration = ConfigurationFactory.getInstance()
.getConfiguration(context, configurationSource());
configuration.initialize();
return configuration;
}
private ConfigurationSource configurationSource() {
try (InputStream in = getClass().getResourceAsStream(getConfigFileName())) {
return new ConfigurationSource(in);
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
}
protected String getConfigFileName() {
return "log4j2.xml";
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free