Search in sources :

Example 6 with LoggerConfiguration

use of org.springframework.boot.logging.LoggerConfiguration in project spring-boot by spring-projects.

the class LogbackLoggingSystemTests method getLoggingConfigurationForALL.

@Test
public void getLoggingConfigurationForALL() throws Exception {
    this.loggingSystem.beforeInitialize();
    this.loggingSystem.initialize(this.initializationContext, null, null);
    Logger logger = this.loggingSystem.getLogger(getClass().getName());
    logger.setLevel(Level.ALL);
    LoggerConfiguration configuration = this.loggingSystem.getLoggerConfiguration(getClass().getName());
    assertThat(configuration).isEqualTo(new LoggerConfiguration(getClass().getName(), LogLevel.TRACE, LogLevel.TRACE));
}
Also used : LoggerConfiguration(org.springframework.boot.logging.LoggerConfiguration) Logger(ch.qos.logback.classic.Logger) Test(org.junit.Test)

Example 7 with LoggerConfiguration

use of org.springframework.boot.logging.LoggerConfiguration in project spring-boot by spring-projects.

the class LoggersEndpointTests method invokeShouldReturnConfigurations.

@Test
@SuppressWarnings("unchecked")
public void invokeShouldReturnConfigurations() throws Exception {
    given(getLoggingSystem().getLoggerConfigurations()).willReturn(Collections.singletonList(new LoggerConfiguration("ROOT", null, LogLevel.DEBUG)));
    given(getLoggingSystem().getSupportedLogLevels()).willReturn(EnumSet.allOf(LogLevel.class));
    Map<String, Object> result = getEndpointBean().invoke();
    Map<String, LoggerLevels> loggers = (Map<String, LoggerLevels>) result.get("loggers");
    Set<LogLevel> levels = (Set<LogLevel>) result.get("levels");
    LoggerLevels rootLevels = loggers.get("ROOT");
    assertThat(rootLevels.getConfiguredLevel()).isNull();
    assertThat(rootLevels.getEffectiveLevel()).isEqualTo("DEBUG");
    assertThat(levels).containsExactly(LogLevel.OFF, LogLevel.FATAL, LogLevel.ERROR, LogLevel.WARN, LogLevel.INFO, LogLevel.DEBUG, LogLevel.TRACE);
}
Also used : LoggerConfiguration(org.springframework.boot.logging.LoggerConfiguration) LoggerLevels(org.springframework.boot.actuate.endpoint.LoggersEndpoint.LoggerLevels) Set(java.util.Set) EnumSet(java.util.EnumSet) Map(java.util.Map) LogLevel(org.springframework.boot.logging.LogLevel) Test(org.junit.Test)

Example 8 with LoggerConfiguration

use of org.springframework.boot.logging.LoggerConfiguration in project spring-boot by spring-projects.

the class LoggersEndpointTests method invokeWhenNameSpecifiedShouldReturnLevels.

public void invokeWhenNameSpecifiedShouldReturnLevels() throws Exception {
    given(getLoggingSystem().getLoggerConfiguration("ROOT")).willReturn(new LoggerConfiguration("ROOT", null, LogLevel.DEBUG));
    LoggerLevels levels = getEndpointBean().invoke("ROOT");
    assertThat(levels.getConfiguredLevel()).isNull();
    assertThat(levels.getEffectiveLevel()).isEqualTo("DEBUG");
}
Also used : LoggerConfiguration(org.springframework.boot.logging.LoggerConfiguration) LoggerLevels(org.springframework.boot.actuate.endpoint.LoggersEndpoint.LoggerLevels)

Example 9 with LoggerConfiguration

use of org.springframework.boot.logging.LoggerConfiguration in project spring-boot by spring-projects.

the class LoggersMvcEndpointTests method getLoggerShouldReturnLogLevels.

@Test
public void getLoggerShouldReturnLogLevels() throws Exception {
    given(this.loggingSystem.getLoggerConfiguration("ROOT")).willReturn(new LoggerConfiguration("ROOT", null, LogLevel.DEBUG));
    this.mvc.perform(get("/loggers/ROOT")).andExpect(status().isOk()).andExpect(content().string(equalTo("{\"configuredLevel\":null," + "\"effectiveLevel\":\"DEBUG\"}")));
}
Also used : LoggerConfiguration(org.springframework.boot.logging.LoggerConfiguration) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with LoggerConfiguration

use of org.springframework.boot.logging.LoggerConfiguration in project spring-boot by spring-projects.

the class JavaLoggingSystemTests method getLoggingConfiguration.

@Test
public void getLoggingConfiguration() throws Exception {
    this.loggingSystem.beforeInitialize();
    this.loggingSystem.initialize(null, null, null);
    this.loggingSystem.setLogLevel(getClass().getName(), LogLevel.DEBUG);
    LoggerConfiguration configuration = this.loggingSystem.getLoggerConfiguration(getClass().getName());
    assertThat(configuration).isEqualTo(new LoggerConfiguration(getClass().getName(), LogLevel.DEBUG, LogLevel.DEBUG));
}
Also used : LoggerConfiguration(org.springframework.boot.logging.LoggerConfiguration) Test(org.junit.Test)

Aggregations

LoggerConfiguration (org.springframework.boot.logging.LoggerConfiguration)12 Test (org.junit.Test)6 LogLevel (org.springframework.boot.logging.LogLevel)4 LoggerLevels (org.springframework.boot.actuate.endpoint.LoggersEndpoint.LoggerLevels)2 Logger (ch.qos.logback.classic.Logger)1 ArrayList (java.util.ArrayList)1 EnumSet (java.util.EnumSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Logger (java.util.logging.Logger)1 Configuration (org.apache.logging.log4j.core.config.Configuration)1 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1