Search in sources :

Example 6 with LogLevel

use of org.springframework.boot.logging.LogLevel 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 7 with LogLevel

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

the class LoggersEndpointMBean method setLogLevel.

@ManagedOperation(description = "Set log level for a given logger")
public void setLogLevel(String loggerName, String logLevel) {
    Assert.notNull(logLevel, "LogLevel must not be null");
    LogLevel level = LogLevel.valueOf(logLevel.toUpperCase());
    getEndpoint().setLogLevel(loggerName, level);
}
Also used : LogLevel(org.springframework.boot.logging.LogLevel) ManagedOperation(org.springframework.jmx.export.annotation.ManagedOperation)

Aggregations

LogLevel (org.springframework.boot.logging.LogLevel)7 LoggerConfiguration (org.springframework.boot.logging.LoggerConfiguration)4 EnumSet (java.util.EnumSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Logger (java.util.logging.Logger)1 Level (org.apache.logging.log4j.Level)1 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)1 Test (org.junit.Test)1 LoggerLevels (org.springframework.boot.actuate.endpoint.LoggersEndpoint.LoggerLevels)1 ManagedOperation (org.springframework.jmx.export.annotation.ManagedOperation)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1