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

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JavaLoggingSystem.java   
protected void loadConfiguration(String location, LogFile logFile) {
    Assert.notNull(location, "Location must not be null");
    try {
        String configuration = FileCopyUtils.copyToString(
                new InputStreamReader(ResourceUtils.getURL(location).openStream()));
        if (logFile != null) {
            configuration = configuration.replace("${LOG_FILE}",
                    StringUtils.cleanPath(logFile.toString()));
        }
        LogManager.getLogManager().readConfiguration(
                new ByteArrayInputStream(configuration.getBytes()));
    }
    catch (Exception ex) {
        throw new IllegalStateException(
                "Could not initialize Java logging from " + location, ex);
    }
}
项目:spring-boot-concourse    文件:JavaLoggingSystem.java   
protected void loadConfiguration(String location, LogFile logFile) {
    Assert.notNull(location, "Location must not be null");
    try {
        String configuration = FileCopyUtils.copyToString(
                new InputStreamReader(ResourceUtils.getURL(location).openStream()));
        if (logFile != null) {
            configuration = configuration.replace("${LOG_FILE}",
                    StringUtils.cleanPath(logFile.toString()));
        }
        LogManager.getLogManager().readConfiguration(
                new ByteArrayInputStream(configuration.getBytes()));
    }
    catch (Exception ex) {
        throw new IllegalStateException(
                "Could not initialize Java logging from " + location, ex);
    }
}
项目:contestparser    文件:JavaLoggingSystem.java   
protected void loadConfiguration(String location, LogFile logFile) {
    Assert.notNull(location, "Location must not be null");
    try {
        String configuration = FileCopyUtils.copyToString(
                new InputStreamReader(ResourceUtils.getURL(location).openStream()));
        if (logFile != null) {
            configuration = configuration.replace("${LOG_FILE}",
                    StringUtils.cleanPath(logFile.toString()));
        }
        LogManager.getLogManager().readConfiguration(
                new ByteArrayInputStream(configuration.getBytes()));
    }
    catch (Exception ex) {
        throw new IllegalStateException(
                "Could not initialize Java logging from " + location, ex);
    }
}
项目:contestparser    文件:Log4J2LoggingSystem.java   
protected void loadConfiguration(String location, LogFile logFile) {
    Assert.notNull(location, "Location must not be null");
    if (logFile != null) {
        logFile.applyToSystemProperties();
    }
    try {
        LoggerContext ctx = getLoggerContext();
        URL url = ResourceUtils.getURL(location);
        ConfigurationSource source = getConfigurationSource(url);
        ctx.start(ConfigurationFactory.getInstance().getConfiguration(source));
    }
    catch (Exception ex) {
        throw new IllegalStateException(
                "Could not initialize Log4J2 logging from " + location, ex);
    }
}
项目: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    文件: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    文件:Log4J2LoggingSystem.java   
protected void loadConfiguration(String location, LogFile logFile) {
    Assert.notNull(location, "Location must not be null");
    try {
        LoggerContext ctx = getLoggerContext();
        URL url = ResourceUtils.getURL(location);
        ConfigurationSource source = getConfigurationSource(url);
        ctx.start(ConfigurationFactory.getInstance().getConfiguration(source));
    }
    catch (Exception ex) {
        throw new IllegalStateException(
                "Could not initialize Log4J2 logging from " + location, ex);
    }
}
项目: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    文件:LogbackLoggingSystemTests.java   
@Test
public void reinitializeShouldSetSystemProperty() throws Exception {
    // gh-5491
    this.loggingSystem.beforeInitialize();
    this.logger.info("Hidden");
    this.loggingSystem.initialize(this.initializationContext, null, null);
    LogFile logFile = getLogFile(tmpDir() + "/example.log", null, false);
    this.loggingSystem.initialize(this.initializationContext,
            "classpath:logback-nondefault.xml", logFile);
    assertThat(System.getProperty("LOG_FILE")).endsWith("example.log");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LogFileMvcEndpoint.java   
private Resource getLogFileResource() {
    if (this.externalFile != null) {
        return new FileSystemResource(this.externalFile);
    }
    LogFile logFile = LogFile.get(getEnvironment());
    if (logFile == null) {
        logger.debug("Missing 'logging.file' or 'logging.path' properties");
        return null;
    }
    return new FileSystemResource(logFile.toString());
}
项目: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    文件: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    文件:Log4J2LoggingSystem.java   
protected void loadConfiguration(String location, LogFile logFile) {
    Assert.notNull(location, "Location must not be null");
    try {
        LoggerContext ctx = getLoggerContext();
        URL url = ResourceUtils.getURL(location);
        ConfigurationSource source = getConfigurationSource(url);
        ctx.start(ConfigurationFactory.getInstance().getConfiguration(source));
    }
    catch (Exception ex) {
        throw new IllegalStateException(
                "Could not initialize Log4J2 logging from " + location, ex);
    }
}
项目: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    文件:LogbackLoggingSystemTests.java   
@Test
public void reinitializeShouldSetSystemProperty() throws Exception {
    // gh-5491
    this.loggingSystem.beforeInitialize();
    this.logger.info("Hidden");
    this.loggingSystem.initialize(this.initializationContext, null, null);
    LogFile logFile = getLogFile(tmpDir() + "/example.log", null, false);
    this.loggingSystem.initialize(this.initializationContext,
            "classpath:logback-nondefault.xml", logFile);
    assertThat(System.getProperty("LOG_FILE")).endsWith("example.log");
}
项目:spring-boot-concourse    文件:LogFileMvcEndpoint.java   
private Resource getLogFileResource() {
    if (this.externalFile != null) {
        return new FileSystemResource(this.externalFile);
    }
    LogFile logFile = LogFile.get(this.environment);
    if (logFile == null) {
        logger.debug("Missing 'logging.file' or 'logging.path' properties");
        return null;
    }
    return new FileSystemResource(logFile.toString());
}
项目: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    文件: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    文件:Log4JLoggingSystem.java   
protected void loadConfiguration(String location, LogFile logFile) {
    Assert.notNull(location, "Location must not be null");
    if (logFile != null) {
        logFile.applyToSystemProperties();
    }
    try {
        Log4jConfigurer.initLogging(location);
    }
    catch (Exception ex) {
        throw new IllegalStateException(
                "Could not initialize Log4J logging from " + location, ex);
    }
}
项目: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    文件:LogFileMvcEndpoint.java   
private Resource getLogFileResource() {
    LogFile logFile = LogFile.get(this.environment);
    if (logFile == null) {
        logger.debug("Missing 'logging.file' or 'logging.path' properties");
        return null;
    }
    FileSystemResource resource = new FileSystemResource(logFile.toString());
    if (!resource.exists()) {
        if (logger.isWarnEnabled()) {
            logger.debug("Log file '" + resource + "' does not exist");
        }
        return null;
    }
    return resource;
}
项目:spring-cloud-commons    文件:PropertySourceBootstrapConfiguration.java   
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    CompositePropertySource composite = new CompositePropertySource(
            BOOTSTRAP_PROPERTY_SOURCE_NAME);
    AnnotationAwareOrderComparator.sort(this.propertySourceLocators);
    boolean empty = true;
    ConfigurableEnvironment environment = applicationContext.getEnvironment();
    for (PropertySourceLocator locator : this.propertySourceLocators) {
        PropertySource<?> source = null;
        source = locator.locate(environment);
        if (source == null) {
            continue;
        }
        logger.info("Located property source: " + source);
        composite.addPropertySource(source);
        empty = false;
    }
    if (!empty) {
        MutablePropertySources propertySources = environment.getPropertySources();
        String logConfig = environment.resolvePlaceholders("${logging.config:}");
        LogFile logFile = LogFile.get(environment);
        if (propertySources.contains(BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
            propertySources.remove(BOOTSTRAP_PROPERTY_SOURCE_NAME);
        }
        insertPropertySources(propertySources, composite);
        reinitializeLoggingSystem(environment, logConfig, logFile);
        setLogLevels(applicationContext, environment);
        handleIncludedProfiles(environment);
    }
}
项目:airsonic    文件:LoggingFileOverrideListener.java   
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    PropertySource ps = new MapPropertySource("LogFileLocationPS",
            Collections.singletonMap(LogFile.FILE_PROPERTY, SettingsService.getLogFile().getAbsolutePath()));
    event.getEnvironment().getPropertySources().addLast(ps);
}
项目: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    文件:Log4J2LoggingSystem.java   
@Override
public void initialize(LoggingInitializationContext initializationContext,
        String configLocation, LogFile logFile) {
    getLoggerContext().getConfiguration().removeFilter(FILTER);
    super.initialize(initializationContext, configLocation, logFile);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:Log4J2LoggingSystem.java   
@Override
protected void loadConfiguration(LoggingInitializationContext initializationContext,
        String location, LogFile logFile) {
    super.loadConfiguration(initializationContext, location, logFile);
    loadConfiguration(location, logFile);
}