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

项目:contestparser    文件:LogbackLoggingSystemTests.java   
@Test
public void testFilePatternProperty() throws Exception {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("logging.pattern.file", "%logger %msg");
    LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(
            environment);
    File file = new File(tmpDir(), "logback-test.log");
    LogFile logFile = getLogFile(file.getPath(), null);
    this.loggingSystem.initialize(loggingInitializationContext, null, logFile);
    this.logger.info("Hello world");
    String output = this.output.toString().trim();
    assertTrue("Wrong console output pattern:\n" + output,
            getLineWithText(output, "Hello world").contains("INFO"));
    assertFalse("Wrong file output pattern:\n" + output,
            getLineWithText(file, "Hello world").contains("INFO"));
}
项目: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");
        }
    }
}
项目:logging-log4j-boot    文件:Log4jLoggingSystem.java   
@Override
protected void loadDefaults(final LoggingInitializationContext context, final LogFile file) {
    final String configFileName = "classpath:META-INF/log4j/default/log4j2"
        + ((file == null) ? Strings.EMPTY : "-file")
        + ".xml";
    loadConfiguration(context, configFileName, file);
}
项目:logging-log4j-boot    文件:Log4jLoggingSystem.java   
@Override
protected void loadConfiguration(final LoggingInitializationContext context, final String location,
                                 final LogFile ignored) {
    // log file name is available via ${sys:LOG_FILE} (see log4j2-file.xml default config)
    final URI configLocation = NetUtils.toURI(location);
    loggerContext = (LoggerContext) LogManager.getContext(
        getClassLoader(), false, this, configLocation);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JavaLoggingSystem.java   
@Override
protected void loadDefaults(LoggingInitializationContext initializationContext,
        LogFile logFile) {
    if (logFile != null) {
        loadConfiguration(getPackagedConfigFile("logging-file.properties"), logFile);
    }
    else {
        loadConfiguration(getPackagedConfigFile("logging.properties"), logFile);
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LogbackLoggingSystem.java   
@Override
public void initialize(LoggingInitializationContext initializationContext,
        String configLocation, LogFile logFile) {
    getLogger(null).getLoggerContext().getTurboFilterList().remove(FILTER);
    super.initialize(initializationContext, configLocation, logFile);
    if (StringUtils.hasText(System.getProperty(CONFIGURATION_FILE_PROPERTY))) {
        getLogger(LogbackLoggingSystem.class.getName()).warn(
                "Ignoring '" + CONFIGURATION_FILE_PROPERTY + "' system property. "
                        + "Please use 'logging.config' instead.");
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LogbackLoggingSystem.java   
@Override
protected void loadDefaults(LoggingInitializationContext initializationContext,
        LogFile logFile) {
    LoggerContext context = getLoggerContext();
    stopAndReset(context);
    LogbackConfigurator configurator = new LogbackConfigurator(context);
    context.putProperty("LOG_LEVEL_PATTERN",
            initializationContext.getEnvironment().resolvePlaceholders(
                    "${logging.pattern.level:${LOG_LEVEL_PATTERN:%5p}}"));
    new DefaultLogbackConfiguration(initializationContext, logFile)
            .apply(configurator);
    context.setPackagingDataEnabled(true);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LogbackLoggingSystem.java   
@Override
protected void loadConfiguration(LoggingInitializationContext initializationContext,
        String location, LogFile logFile) {
    super.loadConfiguration(initializationContext, location, logFile);
    LoggerContext loggerContext = getLoggerContext();
    stopAndReset(loggerContext);
    try {
        configureByResourceUrl(initializationContext, loggerContext,
                ResourceUtils.getURL(location));
    }
    catch (Exception ex) {
        throw new IllegalStateException(
                "Could not initialize Logback logging from " + location, ex);
    }
    List<Status> statuses = loggerContext.getStatusManager().getCopyOfStatusList();
    StringBuilder errors = new StringBuilder();
    for (Status status : statuses) {
        if (status.getLevel() == Status.ERROR) {
            errors.append(errors.length() > 0 ? String.format("%n") : "");
            errors.append(status.toString());
        }
    }
    if (errors.length() > 0) {
        throw new IllegalStateException(
                String.format("Logback configuration error detected: %n%s", errors));
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LogbackLoggingSystem.java   
private void configureByResourceUrl(
        LoggingInitializationContext initializationContext,
        LoggerContext loggerContext, URL url) throws JoranException {
    if (url.toString().endsWith("xml")) {
        JoranConfigurator configurator = new SpringBootJoranConfigurator(
                initializationContext);
        configurator.setContext(loggerContext);
        configurator.doConfigure(url);
    }
    else {
        new ContextInitializer(loggerContext).configureByResource(url);
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:Log4J2LoggingSystem.java   
@Override
protected void loadDefaults(LoggingInitializationContext initializationContext,
        LogFile logFile) {
    if (logFile != null) {
        loadConfiguration(getPackagedConfigFile("log4j2-file.xml"), logFile);
    }
    else {
        loadConfiguration(getPackagedConfigFile("log4j2.xml"), logFile);
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LogbackLoggingSystemTests.java   
@Test
public void testConsolePatternProperty() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("logging.pattern.console", "%logger %msg");
    LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(
            environment);
    this.loggingSystem.initialize(loggingInitializationContext, null, null);
    this.logger.info("Hello world");
    String output = this.output.toString().trim();
    assertThat(getLineWithText(output, "Hello world")).doesNotContain("INFO");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LogbackLoggingSystemTests.java   
@Test
public void testLevelPatternProperty() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("logging.pattern.level", "X%clr(%p)X");
    LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(
            environment);
    this.loggingSystem.initialize(loggingInitializationContext, null, null);
    this.logger.info("Hello world");
    String output = this.output.toString().trim();
    assertThat(getLineWithText(output, "Hello world")).contains("XINFOX");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LogbackLoggingSystemTests.java   
@Test
public void testFilePatternProperty() throws Exception {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("logging.pattern.file", "%logger %msg");
    LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(
            environment);
    File file = new File(tmpDir(), "logback-test.log");
    LogFile logFile = getLogFile(file.getPath(), null);
    this.loggingSystem.initialize(loggingInitializationContext, null, logFile);
    this.logger.info("Hello world");
    String output = this.output.toString().trim();
    assertThat(getLineWithText(output, "Hello world")).contains("INFO");
    assertThat(getLineWithText(file, "Hello world")).doesNotContain("INFO");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SpringBootJoranConfiguratorTests.java   
@Before
public void setup() {
    this.environment = new MockEnvironment();
    this.initializationContext = new LoggingInitializationContext(this.environment);
    this.configurator = new SpringBootJoranConfigurator(this.initializationContext);
    StaticLoggerBinder binder = StaticLoggerBinder.getSingleton();
    this.context = (LoggerContext) binder.getLoggerFactory();
    this.logger = this.context.getLogger(getClass());
}
项目:spring-boot-concourse    文件:JavaLoggingSystem.java   
@Override
protected void loadDefaults(LoggingInitializationContext initializationContext,
        LogFile logFile) {
    if (logFile != null) {
        loadConfiguration(getPackagedConfigFile("logging-file.properties"), logFile);
    }
    else {
        loadConfiguration(getPackagedConfigFile("logging.properties"), logFile);
    }
}
项目:spring-boot-concourse    文件:LogbackLoggingSystem.java   
@Override
public void initialize(LoggingInitializationContext initializationContext,
        String configLocation, LogFile logFile) {
    getLogger(null).getLoggerContext().getTurboFilterList().remove(FILTER);
    super.initialize(initializationContext, configLocation, logFile);
    if (StringUtils.hasText(System.getProperty(CONFIGURATION_FILE_PROPERTY))) {
        getLogger(LogbackLoggingSystem.class.getName()).warn(
                "Ignoring '" + CONFIGURATION_FILE_PROPERTY + "' system property. "
                        + "Please use 'logging.config' instead.");
    }
}
项目:spring-boot-concourse    文件:LogbackLoggingSystem.java   
@Override
protected void loadDefaults(LoggingInitializationContext initializationContext,
        LogFile logFile) {
    LoggerContext context = getLoggerContext();
    stopAndReset(context);
    LogbackConfigurator configurator = new LogbackConfigurator(context);
    context.putProperty("LOG_LEVEL_PATTERN",
            initializationContext.getEnvironment().resolvePlaceholders(
                    "${logging.pattern.level:${LOG_LEVEL_PATTERN:%5p}}"));
    new DefaultLogbackConfiguration(initializationContext, logFile)
            .apply(configurator);
    context.setPackagingDataEnabled(true);
}
项目:spring-boot-concourse    文件:LogbackLoggingSystem.java   
@Override
protected void loadConfiguration(LoggingInitializationContext initializationContext,
        String location, LogFile logFile) {
    super.loadConfiguration(initializationContext, location, logFile);
    LoggerContext loggerContext = getLoggerContext();
    stopAndReset(loggerContext);
    try {
        configureByResourceUrl(initializationContext, loggerContext,
                ResourceUtils.getURL(location));
    }
    catch (Exception ex) {
        throw new IllegalStateException(
                "Could not initialize Logback logging from " + location, ex);
    }
    List<Status> statuses = loggerContext.getStatusManager().getCopyOfStatusList();
    StringBuilder errors = new StringBuilder();
    for (Status status : statuses) {
        if (status.getLevel() == Status.ERROR) {
            errors.append(errors.length() > 0 ? String.format("%n") : "");
            errors.append(status.toString());
        }
    }
    if (errors.length() > 0) {
        throw new IllegalStateException(
                String.format("Logback configuration error detected: %n%s", errors));
    }
}
项目:spring-boot-concourse    文件:LogbackLoggingSystem.java   
private void configureByResourceUrl(
        LoggingInitializationContext initializationContext,
        LoggerContext loggerContext, URL url) throws JoranException {
    if (url.toString().endsWith("xml")) {
        JoranConfigurator configurator = new SpringBootJoranConfigurator(
                initializationContext);
        configurator.setContext(loggerContext);
        configurator.doConfigure(url);
    }
    else {
        new ContextInitializer(loggerContext).configureByResource(url);
    }
}
项目:spring-boot-concourse    文件:Log4J2LoggingSystem.java   
@Override
protected void loadDefaults(LoggingInitializationContext initializationContext,
        LogFile logFile) {
    if (logFile != null) {
        loadConfiguration(getPackagedConfigFile("log4j2-file.xml"), logFile);
    }
    else {
        loadConfiguration(getPackagedConfigFile("log4j2.xml"), logFile);
    }
}
项目:spring-boot-concourse    文件:LogbackLoggingSystemTests.java   
@Test
public void testConsolePatternProperty() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("logging.pattern.console", "%logger %msg");
    LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(
            environment);
    this.loggingSystem.initialize(loggingInitializationContext, null, null);
    this.logger.info("Hello world");
    String output = this.output.toString().trim();
    assertThat(getLineWithText(output, "Hello world")).doesNotContain("INFO");
}
项目:spring-boot-concourse    文件:LogbackLoggingSystemTests.java   
@Test
public void testLevelPatternProperty() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("logging.pattern.level", "X%clr(%p)X");
    LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(
            environment);
    this.loggingSystem.initialize(loggingInitializationContext, null, null);
    this.logger.info("Hello world");
    String output = this.output.toString().trim();
    assertThat(getLineWithText(output, "Hello world")).contains("XINFOX");
}
项目:spring-boot-concourse    文件:LogbackLoggingSystemTests.java   
@Test
public void testFilePatternProperty() throws Exception {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("logging.pattern.file", "%logger %msg");
    LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(
            environment);
    File file = new File(tmpDir(), "logback-test.log");
    LogFile logFile = getLogFile(file.getPath(), null);
    this.loggingSystem.initialize(loggingInitializationContext, null, logFile);
    this.logger.info("Hello world");
    String output = this.output.toString().trim();
    assertThat(getLineWithText(output, "Hello world")).contains("INFO");
    assertThat(getLineWithText(file, "Hello world")).doesNotContain("INFO");
}
项目:spring-boot-concourse    文件:SpringBootJoranConfiguratorTests.java   
@Before
public void setup() {
    this.environment = new MockEnvironment();
    this.initializationContext = new LoggingInitializationContext(this.environment);
    this.configurator = new SpringBootJoranConfigurator(this.initializationContext);
    StaticLoggerBinder binder = StaticLoggerBinder.getSingleton();
    this.context = (LoggerContext) binder.getLoggerFactory();
    this.logger = this.context.getLogger(getClass());
}
项目:contestparser    文件:JavaLoggingSystem.java   
@Override
protected void loadDefaults(LoggingInitializationContext initializationContext,
        LogFile logFile) {
    if (logFile != null) {
        loadConfiguration(getPackagedConfigFile("logging-file.properties"), logFile);
    }
    else {
        loadConfiguration(getPackagedConfigFile("logging.properties"), logFile);
    }
}
项目:contestparser    文件:LogbackLoggingSystem.java   
@Override
public void initialize(LoggingInitializationContext initializationContext,
        String configLocation, LogFile logFile) {
    getLogger(null).getLoggerContext().getTurboFilterList().remove(FILTER);
    super.initialize(initializationContext, configLocation, logFile);
    if (StringUtils.hasText(System.getProperty(CONFIGURATION_FILE_PROPERTY))) {
        getLogger(LogbackLoggingSystem.class.getName()).warn(
                "Ignoring '" + CONFIGURATION_FILE_PROPERTY + "' system property. "
                        + "Please use 'logging.path' instead.");
    }
}
项目:contestparser    文件:LogbackLoggingSystem.java   
@Override
protected void loadDefaults(LoggingInitializationContext initializationContext,
        LogFile logFile) {
    LoggerContext context = getLoggerContext();
    stopAndReset(context);
    LogbackConfigurator configurator = new LogbackConfigurator(context);
    context.putProperty("LOG_LEVEL_PATTERN",
            initializationContext.getEnvironment().resolvePlaceholders(
                    "${logging.pattern.level:${LOG_LEVEL_PATTERN:%5p}}"));
    new DefaultLogbackConfiguration(initializationContext, logFile)
            .apply(configurator);
}
项目:contestparser    文件:LogbackLoggingSystem.java   
@Override
protected void loadConfiguration(LoggingInitializationContext initializationContext,
        String location, LogFile logFile) {
    Assert.notNull(location, "Location must not be null");
    if (logFile != null) {
        logFile.applyToSystemProperties();
    }
    LoggerContext loggerContext = getLoggerContext();
    stopAndReset(loggerContext);
    try {
        configureByResourceUrl(initializationContext, loggerContext,
                ResourceUtils.getURL(location));
    }
    catch (Exception ex) {
        throw new IllegalStateException(
                "Could not initialize Logback logging from " + location, ex);
    }
    List<Status> statuses = loggerContext.getStatusManager().getCopyOfStatusList();
    StringBuilder errors = new StringBuilder();
    for (Status status : statuses) {
        if (status.getLevel() == Status.ERROR) {
            errors.append(errors.length() > 0 ? "\n" : "");
            errors.append(status.toString());
        }
    }
    if (errors.length() > 0) {
        throw new IllegalStateException(
                "Logback configuration error " + "detected: \n" + errors);
    }
}
项目:contestparser    文件:LogbackLoggingSystem.java   
private void configureByResourceUrl(
        LoggingInitializationContext initializationContext,
        LoggerContext loggerContext, URL url) throws JoranException {
    if (url.toString().endsWith("xml")) {
        JoranConfigurator configurator = new SpringBootJoranConfigurator(
                initializationContext);
        configurator.setContext(loggerContext);
        configurator.doConfigure(url);
    }
    else {
        new ContextInitializer(loggerContext).configureByResource(url);
    }
}
项目:contestparser    文件:Log4JLoggingSystem.java   
@Override
protected void loadDefaults(LoggingInitializationContext initializationContext,
        LogFile logFile) {
    if (logFile != null) {
        loadConfiguration(getPackagedConfigFile("log4j-file.properties"), logFile);
    }
    else {
        loadConfiguration(getPackagedConfigFile("log4j.properties"), logFile);
    }
}
项目:contestparser    文件:Log4J2LoggingSystem.java   
@Override
protected void loadDefaults(LoggingInitializationContext initializationContext,
        LogFile logFile) {
    if (logFile != null) {
        loadConfiguration(getPackagedConfigFile("log4j2-file.xml"), logFile);
    }
    else {
        loadConfiguration(getPackagedConfigFile("log4j2.xml"), logFile);
    }
}
项目:contestparser    文件:LogbackLoggingSystemTests.java   
@Test
public void testConsolePatternProperty() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("logging.pattern.console", "%logger %msg");
    LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(
            environment);
    this.loggingSystem.initialize(loggingInitializationContext, null, null);
    this.logger.info("Hello world");
    String output = this.output.toString().trim();
    assertFalse("Wrong output pattern:\n" + output,
            getLineWithText(output, "Hello world").contains("INFO"));
}
项目:contestparser    文件:LogbackLoggingSystemTests.java   
@Test
public void testLevelPatternProperty() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("logging.pattern.level", "X%clr(%p)X");
    LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(
            environment);
    this.loggingSystem.initialize(loggingInitializationContext, null, null);
    this.logger.info("Hello world");
    String output = this.output.toString().trim();
    assertTrue("Wrong output pattern:\n" + output,
            getLineWithText(output, "Hello world").contains("XINFOX"));
}
项目:contestparser    文件:SpringBootJoranConfiguratorTests.java   
@Before
public void setup() {
    this.environment = new MockEnvironment();
    this.initializationContext = new LoggingInitializationContext(this.environment);
    this.configurator = new SpringBootJoranConfigurator(this.initializationContext);
    StaticLoggerBinder binder = StaticLoggerBinder.getSingleton();
    this.context = (LoggerContext) binder.getLoggerFactory();
    this.logger = this.context.getLogger(getClass());
}
项目:logging-log4j-boot    文件:Log4jLoggingSystem.java   
@Override
protected void reinitialize(final LoggingInitializationContext context) {
    if (loggerContext != null) {
        loggerContext.reconfigure();
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JavaLoggingSystem.java   
@Override
protected void loadConfiguration(LoggingInitializationContext initializationContext,
        String location, LogFile logFile) {
    loadConfiguration(location, logFile);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:DefaultLogbackConfiguration.java   
DefaultLogbackConfiguration(LoggingInitializationContext initializationContext,
        LogFile logFile) {
    this.patterns = getPatternsResolver(initializationContext.getEnvironment());
    this.logFile = logFile;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SpringBootJoranConfigurator.java   
SpringBootJoranConfigurator(LoggingInitializationContext initializationContext) {
    this.initializationContext = initializationContext;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LogbackLoggingSystem.java   
@Override
protected void reinitialize(LoggingInitializationContext initializationContext) {
    getLoggerContext().reset();
    getLoggerContext().getStatusManager().clear();
    loadConfiguration(initializationContext, getSelfInitializationConfig(), null);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:Log4J2LoggingSystem.java   
@Override
public void initialize(LoggingInitializationContext initializationContext,
        String configLocation, LogFile logFile) {
    getLoggerContext().getConfiguration().removeFilter(FILTER);
    super.initialize(initializationContext, configLocation, logFile);
}