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

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

Introduction

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

Prototype

public abstract void beforeInitialize();

Source Link

Document

Reset the logging system to be limit output.

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  w w  w.  j a  v a2 s.com
    LoggingSystem loggingSystem = LoggingSystem.get(springApplication.getClass().getClassLoader());
    loggingSystem.beforeInitialize();
}

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 {/*ww  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.
 *//*w w w .j  a v a  2 s  .c  o  m*/
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);
    }
}