org.springframework.boot.logging.LogFile Java Examples

The following examples show how to use org.springframework.boot.logging.LogFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogbackLoggingSystem.java    From super-cloudops with Apache License 2.0 6 votes vote down vote up
@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));
	}
}
 
Example #2
Source File: PropertySourceBootstrapConfiguration.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
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("Error opening logging config file " + logConfig, ex);
		}
	}
}
 
Example #3
Source File: SpacedLogbackSystem.java    From spring-cloud-formula with Apache License 2.0 5 votes vote down vote up
protected Appender<ILoggingEvent> fileAppender(Space space) {
    RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    String logPattern = this.patterns.getProperty("logging.pattern.file", FILE_LOG_PATTERN);
    encoder.setPattern(OptionHelper.substVars(logPattern, context));
    encoder.setCharset(DEFAULT_CHARSET);
    appender.setEncoder(encoder);
    start(encoder);

    // parse path and file
    // first consider spec.path, second, default_spec.path, third logging.path
    LogFile logFile = LogFile.get(patterns);
    Properties defaultProperties = new Properties();
    if (logFile != null) {
        logFile.applyTo(defaultProperties);
    }
    String path = space.getSpec().getPath() != null ? space.getSpec().getPath() :
            space.getDefaultSpec().getPath() != null ? space.getDefaultSpec().getPath() :
                    defaultProperties.contains(LoggingSystemProperties.LOG_PATH)
                            ? defaultProperties.getProperty(LoggingSystemProperties.LOG_PATH) :
                            DEFAULT_PATH;
    path = patterns.resolvePlaceholders(path);
    String file = space.getSpec().getFile() != null
            ? fileName(space.getSpec().getFile()) : fileName(space.getName());
    file = patterns.resolvePlaceholders(file);
    appender.setFile(path + "/" + file);
    setRollingPolicy(appender, space, path, file);

    //  threshold config
    ThresholdFilter thresholdFilter = new ThresholdFilter();
    if (space.getSpec().getThreshold() != null) {
        thresholdFilter.setLevel(space.getSpec().getThreshold());
        start(thresholdFilter);
        appender.addFilter(thresholdFilter);
    }

    appender("SPACE-" + space.getName(), appender);
    return appender;
}
 
Example #4
Source File: ConsoleEndpoint.java    From Cleanstone with MIT License 5 votes vote down vote up
private Resource getLogFileResource() {
    if (this.externalFile != null) {
        return new FileSystemResource(this.externalFile.toFile());
    }
    LogFile logFile = LogFile.get(this.environment);
    if (logFile == null) {
        log.debug("Missing 'logging.file' or 'logging.path' properties");
        return null;
    }
    return new FileSystemResource(logFile.toString());
}
 
Example #5
Source File: LogbackLoggingSystem.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(LoggingInitializationContext initializationContext, String configLocation, LogFile logFile) {
	LoggerContext loggerContext = getLoggerContext();
	if (isAlreadyInitialized(loggerContext)) {
		return;
	}
	loggerContext.getTurboFilterList().remove(FILTER);
	super.initialize(initializationContext, configLocation, logFile);
	markAsInitialized(loggerContext);
	if (StringUtils.hasText(System.getProperty(CONFIGURATION_FILE_PROPERTY))) {
		getLogger(LogbackLoggingSystem.class.getName()).warn(
				"Ignoring '" + CONFIGURATION_FILE_PROPERTY + "' system property. " + "Please use 'logging.config' instead.");
	}
}
 
Example #6
Source File: LogbackLoggingSystem.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@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 EnhancedLogbackConfiguration(initializationContext, logFile).apply(configurator);
	context.setPackagingDataEnabled(true);
}
 
Example #7
Source File: Log4j2CloudConfigLoggingSystem.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void loadDefaults(LoggingInitializationContext initializationContext, LogFile logFile) {
    if (logFile != null) {
        this.loadConfiguration(this.getBootPackagedConfigFile("log4j2-file.xml"), logFile);
    } else {
        this.loadConfiguration(this.getBootPackagedConfigFile("log4j2.xml"), logFile);
    }
}
 
Example #8
Source File: LoggingFileOverrideListener.java    From airsonic-advanced with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    PropertySource ps = new MapPropertySource("LogFileLocationPS",
            Collections.singletonMap(LogFile.FILE_PROPERTY, SettingsService.getLogFile().toAbsolutePath().toString()));
    event.getEnvironment().getPropertySources().addLast(ps);
}
 
Example #9
Source File: FormulaLogbackSystem.java    From spring-cloud-formula with Apache License 2.0 4 votes vote down vote up
@Override
protected void loadDefaults(LoggingInitializationContext initializationContext, LogFile logFile) {
    beforeLoadSpaces(initializationContext);
    super.loadDefaults(initializationContext, logFile);
    loadSpaces(initializationContext);
}
 
Example #10
Source File: FormulaLogbackSystem.java    From spring-cloud-formula with Apache License 2.0 4 votes vote down vote up
@Override
protected void loadConfiguration(LoggingInitializationContext initializationContext, String location, LogFile logFile) {
    beforeLoadSpaces(initializationContext);
    super.loadConfiguration(initializationContext, location, logFile);
    loadSpaces(initializationContext);
}
 
Example #11
Source File: EnhancedLogbackConfiguration.java    From super-cloudops with Apache License 2.0 4 votes vote down vote up
EnhancedLogbackConfiguration(LoggingInitializationContext initializationContext, LogFile logFile) {
	this.logging = getPatternsResolver(initializationContext.getEnvironment());
	this.logFile = logFile;
}
 
Example #12
Source File: LoggingFileOverrideListener.java    From airsonic with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    PropertySource ps = new MapPropertySource("LogFileLocationPS",
            Collections.singletonMap(LogFile.FILE_PROPERTY, SettingsService.getLogFile().getAbsolutePath()));
    event.getEnvironment().getPropertySources().addLast(ps);
}
 
Example #13
Source File: Log4j2CloudConfigLoggingSystem.java    From logging-log4j2 with Apache License 2.0 2 votes vote down vote up
/**
 * Set the environment into the ExternalContext field so that it can be obtained by SpringLookup when it
 * is constructed. Spring will replace the ExternalContext field with a String once initialization is
 * complete.
 * @param initializationContext The initialization context.
 * @param configLocation The configuration location.
 * @param logFile the log file.
 */
@Override
public void initialize(LoggingInitializationContext initializationContext, String configLocation, LogFile logFile) {
    getLoggerContext().putObjectIfAbsent(ENVIRONMENT_KEY, initializationContext.getEnvironment());
    super.initialize(initializationContext, configLocation, logFile);
}