Example usage for org.springframework.boot.logging LoggingSystem get

List of usage examples for org.springframework.boot.logging LoggingSystem get

Introduction

In this page you can find the example usage for org.springframework.boot.logging LoggingSystem get.

Prototype

public static LoggingSystem get(ClassLoader classLoader) 

Source Link

Document

Detect and return the logging system in use.

Usage

From source file:org.springframework.boot.context.initializer.LoggingApplicationContextInitializer.java

@Override
public void initialize(SpringApplication springApplication, String[] args) {
    if (System.getProperty("PID") == null) {
        System.setProperty("PID", getPid());
    }//from www .  j a  v a2 s  .  c  o  m
    LoggingSystem loggingSystem = LoggingSystem.get(springApplication.getClass().getClassLoader());
    loggingSystem.beforeInitialize();
}

From source file:org.springframework.boot.context.initializer.LoggingApplicationContextInitializer.java

/**
 * Initialize the logging system according to preferences expressed through the
 * {@link Environment} and the classpath.
 *///from  w  w  w  .  j  a  va2 s .c o  m
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {

    ConfigurableEnvironment environment = applicationContext.getEnvironment();

    if (this.parseArgs && this.springBootLogging == null) {
        if (environment.containsProperty("debug")) {
            this.springBootLogging = LogLevel.DEBUG;
        }
        if (environment.containsProperty("trace")) {
            this.springBootLogging = LogLevel.TRACE;
        }
    }

    for (Map.Entry<String, String> mapping : ENVIRONMENT_SYSTEM_PROPERTY_MAPPING.entrySet()) {
        if (environment.containsProperty(mapping.getKey())) {
            System.setProperty(mapping.getValue(), environment.getProperty(mapping.getKey()));
        }
    }

    LoggingSystem system = LoggingSystem.get(applicationContext.getClassLoader());

    // User specified configuration
    if (environment.containsProperty("logging.config")) {
        String value = environment.getProperty("logging.config");
        try {
            ResourceUtils.getURL(value).openStream().close();
            system.initialize(value);
            return;
        } catch (Exception ex) {
            // Swallow exception and continue
        }
        this.logger.warn("Logging environment value '" + value + "' cannot be opened and will be ignored");
    }

    system.initialize();
    if (this.springBootLogging != null) {
        initializeLogLevel(system, this.springBootLogging);
    }
}

From source file:org.springframework.boot.context.listener.LoggingApplicationListener.java

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof SpringApplicationEnvironmentAvailableEvent) {
        SpringApplicationEnvironmentAvailableEvent available = (SpringApplicationEnvironmentAvailableEvent) event;
        initialize(available.getEnvironment(), available.getSpringApplication().getClassLoader());
    } else {//from  w  w w. j av  a  2 s .com
        if (System.getProperty("PID") == null) {
            System.setProperty("PID", getPid());
        }
        LoggingSystem loggingSystem = LoggingSystem.get(ClassUtils.getDefaultClassLoader());
        loggingSystem.beforeInitialize();
    }
}

From source file:org.springframework.boot.context.listener.LoggingApplicationListener.java

/**
 * Initialize the logging system according to preferences expressed through the
 * {@link Environment} and the classpath.
 *//*from www . ja v a  2 s . c  om*/
protected void initialize(ConfigurableEnvironment environment, ClassLoader classLoader) {

    if (this.parseArgs && this.springBootLogging == null) {
        if (environment.containsProperty("debug")) {
            this.springBootLogging = LogLevel.DEBUG;
        }
        if (environment.containsProperty("trace")) {
            this.springBootLogging = LogLevel.TRACE;
        }
    }

    boolean environmentChanged = false;
    for (Map.Entry<String, String> mapping : ENVIRONMENT_SYSTEM_PROPERTY_MAPPING.entrySet()) {
        if (environment.containsProperty(mapping.getKey())) {
            System.setProperty(mapping.getValue(), environment.getProperty(mapping.getKey()));
            environmentChanged = true;
        }
    }

    LoggingSystem system = LoggingSystem.get(classLoader);

    if (environmentChanged) {
        // Re-initialize the defaults in case the Environment changed
        system.beforeInitialize();
    }
    // User specified configuration
    if (environment.containsProperty("logging.config")) {
        String value = environment.getProperty("logging.config");
        try {
            ResourceUtils.getURL(value).openStream().close();
            system.initialize(value);
            return;
        } catch (Exception ex) {
            // Swallow exception and continue
        }
        this.logger.warn("Logging environment value '" + value + "' cannot be opened and will be ignored");
    }

    system.initialize();
    if (this.springBootLogging != null) {
        initializeLogLevel(system, this.springBootLogging);
    }
}

From source file:org.springframework.boot.context.logging.LoggingApplicationListener.java

private void onApplicationStartingEvent(ApplicationStartingEvent event) {
    this.loggingSystem = LoggingSystem.get(event.getSpringApplication().getClassLoader());
    this.loggingSystem.beforeInitialize();
}

From source file:org.springframework.boot.context.logging.LoggingApplicationListener.java

private void onApplicationEnvironmentPreparedEvent(ApplicationEnvironmentPreparedEvent event) {
    if (this.loggingSystem == null) {
        this.loggingSystem = LoggingSystem.get(event.getSpringApplication().getClassLoader());
    }/*from  w w  w . ja  v  a 2 s  . c  om*/
    initialize(event.getEnvironment(), event.getSpringApplication().getClassLoader());
}

From source file:org.springframework.boot.context.logging.LoggingApplicationListenerTests.java

@After
public void clear() {
    LoggingSystem loggingSystem = LoggingSystem.get(getClass().getClassLoader());
    loggingSystem.setLogLevel("ROOT", LogLevel.INFO);
    loggingSystem.cleanUp();/*from w  w  w.j a  v a 2 s.  co  m*/
    System.clearProperty(LoggingSystem.class.getName());
    System.clearProperty(LoggingSystemProperties.LOG_FILE);
    System.clearProperty(LoggingSystemProperties.LOG_PATH);
    System.clearProperty(LoggingSystemProperties.PID_KEY);
    System.clearProperty(LoggingSystemProperties.EXCEPTION_CONVERSION_WORD);
    System.clearProperty(LoggingSystemProperties.CONSOLE_LOG_PATTERN);
    System.clearProperty(LoggingSystemProperties.FILE_LOG_PATTERN);
    System.clearProperty(LoggingSystemProperties.LOG_LEVEL_PATTERN);
    System.clearProperty(LoggingSystem.SYSTEM_PROPERTY);
    if (this.context != null) {
        this.context.close();
    }
}

From source file:org.springframework.boot.logging.LoggingApplicationListener.java

private void onApplicationStartedEvent(ApplicationStartedEvent event) {
    this.loggingSystem = LoggingSystem.get(event.getSpringApplication().getClassLoader());
    this.loggingSystem.beforeInitialize();
}

From source file:org.springframework.boot.logging.LoggingApplicationListenerTests.java

@After
public void clear() {
    LoggingSystem.get(getClass().getClassLoader()).cleanUp();
    System.clearProperty(LoggingSystem.class.getName());
    System.clearProperty("LOG_FILE");
    System.clearProperty("LOG_PATH");
    System.clearProperty("PID");
    System.clearProperty("LOG_EXCEPTION_CONVERSION_WORD");
    if (this.context != null) {
        this.context.close();
    }//from   www .  j  a v a 2  s  .  com
}

From source file:org.springframework.cloud.logging.LoggingRebinder.java

@Override
public void onApplicationEvent(EnvironmentChangeEvent event) {
    if (this.environment == null) {
        return;//www.  j av  a2 s. c  o m
    }
    LoggingSystem system = LoggingSystem.get(LoggingSystem.class.getClassLoader());
    setLogLevels(system, this.environment);
}