org.springframework.boot.logging.LoggingInitializationContext Java Examples
The following examples show how to use
org.springframework.boot.logging.LoggingInitializationContext.
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 |
@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 |
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: LogbackLoggingSystem.java From super-cloudops with Apache License 2.0 | 5 votes |
@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 #4
Source File: LogbackLoggingSystem.java From super-cloudops with Apache License 2.0 | 5 votes |
@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 #5
Source File: LogbackLoggingSystem.java From super-cloudops with Apache License 2.0 | 5 votes |
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); } }
Example #6
Source File: Log4j2CloudConfigLoggingSystem.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@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 #7
Source File: Target_LogbackLoggingSystem.java From spring-graalvm-native with Apache License 2.0 | 4 votes |
@Substitute private void configureByResourceUrl(LoggingInitializationContext initializationContext, LoggerContext loggerContext, URL url) throws JoranException { throw new UnsupportedOperationException("XML support disabled"); }
Example #8
Source File: FormulaLogbackSystem.java From spring-cloud-formula with Apache License 2.0 | 4 votes |
@Override protected void loadDefaults(LoggingInitializationContext initializationContext, LogFile logFile) { beforeLoadSpaces(initializationContext); super.loadDefaults(initializationContext, logFile); loadSpaces(initializationContext); }
Example #9
Source File: FormulaLogbackSystem.java From spring-cloud-formula with Apache License 2.0 | 4 votes |
@Override protected void loadConfiguration(LoggingInitializationContext initializationContext, String location, LogFile logFile) { beforeLoadSpaces(initializationContext); super.loadConfiguration(initializationContext, location, logFile); loadSpaces(initializationContext); }
Example #10
Source File: SpringBootJoranConfigurator.java From super-cloudops with Apache License 2.0 | 4 votes |
SpringBootJoranConfigurator(LoggingInitializationContext initializationContext) { this.initializationContext = initializationContext; }
Example #11
Source File: LogbackLoggingSystem.java From super-cloudops with Apache License 2.0 | 4 votes |
@Override protected void reinitialize(LoggingInitializationContext initializationContext) { getLoggerContext().reset(); getLoggerContext().getStatusManager().clear(); loadConfiguration(initializationContext, getSelfInitializationConfig(), null); }
Example #12
Source File: EnhancedLogbackConfiguration.java From super-cloudops with Apache License 2.0 | 4 votes |
EnhancedLogbackConfiguration(LoggingInitializationContext initializationContext, LogFile logFile) { this.logging = getPatternsResolver(initializationContext.getEnvironment()); this.logFile = logFile; }
Example #13
Source File: Log4j2CloudConfigLoggingSystem.java From logging-log4j2 with Apache License 2.0 | 2 votes |
/** * 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); }