Java 类org.springframework.boot.logging.LoggingSystem 实例源码

项目:spring-cloud-commons    文件:PropertySourceBootstrapConfiguration.java   
private void reinitializeLoggingSystem(ConfigurableEnvironment environment,
        String oldLogConfig, LogFile oldLogFile) {
    Map<String, Object> props = Binder.get(environment)
            .bind("logging", Bindable.mapOf(String.class, Object.class)).orElseGet(Collections::emptyMap);
    if (!props.isEmpty()) {
        String logConfig = environment.resolvePlaceholders("${logging.config:}");
        LogFile logFile = LogFile.get(environment);
        LoggingSystem system = LoggingSystem
                .get(LoggingSystem.class.getClassLoader());
        try {
            ResourceUtils.getURL(logConfig).openStream().close();
            // Three step initialization that accounts for the clean up of the logging
            // context before initialization. Spring Boot doesn't initialize a logging
            // system that hasn't had this sequence applied (since 1.4.1).
            system.cleanUp();
            system.beforeInitialize();
            system.initialize(new LoggingInitializationContext(environment),
                    logConfig, logFile);
        }
        catch (Exception ex) {
            PropertySourceBootstrapConfiguration.logger
                    .warn("Logging config file location '" + logConfig
                            + "' cannot be opened and will be ignored");
        }
    }
}
项目:spring-cloud-commons    文件:ContextRefresherTests.java   
@Test
public void loggingSystemNotInitialized() {
    System.setProperty(LoggingSystem.SYSTEM_PROPERTY,
            TestLoggingSystem.class.getName());
    TestLoggingSystem system = (TestLoggingSystem) LoggingSystem
            .get(getClass().getClassLoader());
    assertThat(system.getCount()).isEqualTo(0);
    try (ConfigurableApplicationContext context = SpringApplication.run(Empty.class,
            "--spring.main.webEnvironment=false", "--debug=false",
            "--spring.main.bannerMode=OFF",
            "--spring.cloud.bootstrap.name=refresh")) {
        assertThat(system.getCount()).isEqualTo(4);
        ContextRefresher refresher = new ContextRefresher(context, scope);
        refresher.refresh();
        assertThat(system.getCount()).isEqualTo(4);
    }
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void logTrace() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.TRACE);
    logger.log(LogLevel.TRACE, "logger name", "trace message");
    assertThat(capture.toString(), containsString("TRACE logger name - trace message"));
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void logTraceError() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.TRACE);
    logger.log(LogLevel.TRACE, "logger name", "trace message", new Exception("error message"));
    Pattern pattern = Pattern.compile("TRACE logger name - trace message.*java.lang.Exception: error message",
            Pattern.DOTALL | Pattern.MULTILINE);
    assertTrue(pattern.matcher(capture.toString()).find());
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void logDebug() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.DEBUG);
    logger.log(LogLevel.DEBUG, "logger name", "debug message");
    assertThat(capture.toString(), containsString("DEBUG logger name - debug message"));
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void logDebugError() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.DEBUG);
    logger.log(LogLevel.DEBUG, "logger name", "debug message", new Exception("error message"));
    Pattern pattern = Pattern.compile("DEBUG logger name - debug message.*java.lang.Exception: error message",
            Pattern.DOTALL | Pattern.MULTILINE);
    assertTrue(pattern.matcher(capture.toString()).find());
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void logInfo() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.INFO);
    logger.log(LogLevel.INFO, "logger name", "info message");
    assertThat(capture.toString(), containsString("INFO logger name - info message"));
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void logInfoError() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.INFO);
    logger.log(LogLevel.INFO, "logger name", "info message", new Exception("error message"));
    Pattern pattern = Pattern.compile("INFO logger name - info message.*java.lang.Exception: error message",
            Pattern.DOTALL | Pattern.MULTILINE);
    assertTrue(pattern.matcher(capture.toString()).find());
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void logWarning() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.WARN);
    logger.log(LogLevel.WARN, "logger name", "warn message");
    assertThat(capture.toString(), containsString("WARN logger name - warn message"));
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void logWarningError() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.WARN);
    logger.log(LogLevel.WARN, "logger name", "warn message", new Exception("error message"));
    Pattern pattern = Pattern.compile("WARN logger name - warn message.*java.lang.Exception: error message",
            Pattern.DOTALL | Pattern.MULTILINE);
    assertTrue(pattern.matcher(capture.toString()).find());
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void logError() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.ERROR);
    logger.log(LogLevel.ERROR, "logger name", "error message");
    assertThat(capture.toString(), containsString("ERROR logger name - error message"));
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void logErrorError() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.ERROR);
    logger.log(LogLevel.ERROR, "logger name", "error message", new Exception("error message"));
    Pattern pattern = Pattern.compile("ERROR logger name - error message.*java.lang.Exception: error message",
            Pattern.DOTALL | Pattern.MULTILINE);
    assertTrue(pattern.matcher(capture.toString()).find());
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void logFatal() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.FATAL);
    logger.log(LogLevel.FATAL, "logger name", "fatal message");
    assertThat(capture.toString(), containsString("ERROR logger name - fatal message"));
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void logFatalError() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.FATAL);
    logger.log(LogLevel.FATAL, "logger name", "fatal message", new Exception("error message"));
    Pattern pattern = Pattern.compile("ERROR logger name - fatal message.*java.lang.Exception: error message",
            Pattern.DOTALL | Pattern.MULTILINE);
    assertTrue(pattern.matcher(capture.toString()).find());
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void logTraceErrorOff() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.OFF);
    logger.log(LogLevel.TRACE, "logger name", "trace message", new Exception("error message"));
    Pattern pattern = Pattern.compile("TRACE logger name - trace message.*java.lang.Exception: error message",
            Pattern.DOTALL | Pattern.MULTILINE);
    assertFalse(pattern.matcher(capture.toString()).find());
}
项目:logging-log4j-boot    文件:PrebootConfigurationFactory.java   
@Override
public Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) {
    if (source != null && source != ConfigurationSource.NULL_SOURCE) {
        if (LoggingSystem.get(loggerContext.getClass().getClassLoader()) != null) {
            return new DefaultConfiguration();
        }
    }
    return null;
}
项目:artifactory-resource    文件:DebugLogging.java   
public static void setEnabled(boolean enabled) {
    if (enabled) {
        LoggingSystem system = LoggingSystem
                .get(Thread.currentThread().getContextClassLoader());
        system.setLogLevel("org.springframework", LogLevel.DEBUG);
        system.setLogLevel("io.spring.concourse.artifactoryresource", LogLevel.DEBUG);
    }
}
项目:spring-cloud-commons    文件:LoggingRebinder.java   
@Override
public void onApplicationEvent(EnvironmentChangeEvent event) {
    if (this.environment == null) {
        return;
    }
    LoggingSystem system = LoggingSystem.get(LoggingSystem.class.getClassLoader());
    setLogLevels(system, this.environment);
}
项目:spring-cloud-commons    文件:LoggingRebinder.java   
protected void setLogLevels(LoggingSystem system, Environment environment) {
    Map<String, String> levels = Binder.get(environment)
            .bind("logging.level", STRING_STRING_MAP).orElseGet(Collections::emptyMap);
    for (Entry<String, String> entry : levels.entrySet()) {
        setLogLevel(system, environment, entry.getKey(), entry.getValue().toString());
    }
}
项目:spring-cloud-commons    文件:LoggingRebinder.java   
private void setLogLevel(LoggingSystem system, Environment environment, String name,
        String level) {
    try {
        if (name.equalsIgnoreCase("root")) {
            name = null;
        }
        level = environment.resolvePlaceholders(level);
        system.setLogLevel(name, LogLevel.valueOf(level.toUpperCase()));
    }
    catch (RuntimeException ex) {
        this.logger.error("Cannot set level: " + level + " for '" + name + "'");
    }
}
项目:logger-spring-boot    文件:LoggableTest.java   
@BeforeClass
public static void setErrorLogging() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader()).setLogLevel(Logger.ROOT_LOGGER_NAME, LogLevel.DEBUG);
}
项目:logger-spring-boot    文件:LoggableOverrideFormatsTest.java   
@BeforeClass
public static void setErrorLogging() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader()).setLogLevel(Logger.ROOT_LOGGER_NAME, LogLevel.INFO);
}
项目:logger-spring-boot    文件:LoggableOverride2FormatsTest.java   
@BeforeClass
public static void setErrorLogging() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader()).setLogLevel(Logger.ROOT_LOGGER_NAME, LogLevel.INFO);
}
项目:logger-spring-boot    文件:LoggableErrorLevelTest.java   
@BeforeClass
public static void setErrorLogging() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader()).setLogLevel(Logger.ROOT_LOGGER_NAME, LogLevel.ERROR);
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void isLogTraceEnabled() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.TRACE);
    assertTrue(logger.isEnabled(LogLevel.TRACE, "logger name"));
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void isLogDebugEnabled() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.DEBUG);
    assertTrue(logger.isEnabled(LogLevel.DEBUG, "logger name"));
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void isLogInfoEnabled() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.INFO);
    assertTrue(logger.isEnabled(LogLevel.INFO, "logger name"));
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void isLogErrorEnabled() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.ERROR);
    assertTrue(logger.isEnabled(LogLevel.ERROR, "logger name"));
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void isLogFatalEnabled() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.FATAL);
    assertTrue(logger.isEnabled(LogLevel.FATAL, "logger name"));
}
项目:logger-spring-boot    文件:LoggerTest.java   
@Test
public void isLogTraceDisabled() {
    LoggingSystem.get(ClassLoader.getSystemClassLoader())
            .setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.OFF);
    assertFalse(logger.isEnabled(LogLevel.TRACE, "logger name"));
}
项目:generator-jhipster-grpc    文件:_LoggersService.java   
public LoggersService(LoggingSystem loggingSystem) {
    Assert.notNull(loggingSystem, "LoggingSystem must not be null");
    this.loggingSystem = loggingSystem;
}
项目:spring-cloud-commons    文件:LoggingSystemShutdownListener.java   
private void shutdownLogging() {
    LoggingSystem loggingSystem = LoggingSystem
            .get(ClassUtils.getDefaultClassLoader());
    loggingSystem.cleanUp();
    loggingSystem.beforeInitialize();
}
项目:spring-cloud-commons    文件:LoggingRebinderTests.java   
@After
public void reset() {
    LoggingSystem.get(getClass().getClassLoader())
            .setLogLevel("org.springframework.web", LogLevel.INFO);
}
项目:spring-cloud-commons    文件:ContextRefresherTests.java   
@After
public void close() {
    System.clearProperty(LoggingSystem.SYSTEM_PROPERTY);
    TestLoggingSystem.count = 0;
}