Java Code Examples for org.springframework.boot.logging.LoggingSystem#get()

The following examples show how to use org.springframework.boot.logging.LoggingSystem#get() . 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: 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 2
Source File: ContextRefresherTests.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void loggingSystemNotInitialized() {
	System.setProperty(LoggingSystem.SYSTEM_PROPERTY,
			TestLoggingSystem.class.getName());
	TestLoggingSystem system = (TestLoggingSystem) LoggingSystem
			.get(getClass().getClassLoader());
	then(system.getCount()).isEqualTo(0);
	try (ConfigurableApplicationContext context = SpringApplication.run(Empty.class,
			"--spring.main.web-application-type=none", "--debug=false",
			"--spring.main.bannerMode=OFF",
			"--spring.cloud.bootstrap.name=refresh")) {
		then(system.getCount()).isEqualTo(4);
		ContextRefresher refresher = new ContextRefresher(context, this.scope);
		refresher.refresh();
		then(system.getCount()).isEqualTo(4);
	}
}
 
Example 3
Source File: LoggingDslTests.java    From spring-fu with Apache License 2.0 5 votes vote down vote up
@Test
void changeDefaultROOTLogLevel() {
	var app = application(it -> it.logging(log -> log.level(LogLevel.DEBUG)));
	app.run();
	var loggingSystem = LoggingSystem.get(LoggingDslTests.class.getClassLoader());
	assertEquals(LogLevel.DEBUG, loggingSystem.getLoggerConfiguration("ROOT").getEffectiveLevel());
}
 
Example 4
Source File: LoggingDslTests.java    From spring-fu with Apache License 2.0 5 votes vote down vote up
@Test
void changePackageLogLevel() {
	var packageName = "org.springframework";
	var app = application(it -> it.logging(log -> log.level(packageName, LogLevel.DEBUG)));
	app.run();
	var loggingSystem = LoggingSystem.get(LoggingDslTests.class.getClassLoader());
	assertEquals(LogLevel.DEBUG, loggingSystem.getLoggerConfiguration(packageName).getEffectiveLevel());
}
 
Example 5
Source File: LoggingDslTests.java    From spring-fu with Apache License 2.0 5 votes vote down vote up
@Test
void changeClassLogLevel() {
	var loggingSystem = LoggingSystem.get(LoggingDslTests.class.getClassLoader());
	loggingSystem.setLogLevel("ROOT", LogLevel.INFO);
	var app = application(it -> it.logging(log -> log.level(DefaultListableBeanFactory.class, LogLevel.DEBUG)));
	app.run();
	assertEquals(LogLevel.DEBUG, loggingSystem.getLoggerConfiguration("org.springframework.beans.factory.support.DefaultListableBeanFactory").getEffectiveLevel());
}
 
Example 6
Source File: DebugLogging.java    From artifactory-resource with Apache License 2.0 5 votes vote down vote up
static void setEnabled(boolean enabled) {
	if (enabled) {
		LoggingSystem system = LoggingSystem.get(Thread.currentThread().getContextClassLoader());
		system.setLogLevel("org.springframework", LogLevel.DEBUG);
		system.setLogLevel("io.spring.concourse.artifactoryresource", LogLevel.DEBUG);
	}
}
 
Example 7
Source File: LoggingRebinder.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(EnvironmentChangeEvent event) {
	if (this.environment == null) {
		return;
	}
	LoggingSystem system = LoggingSystem.get(LoggingSystem.class.getClassLoader());
	setLogLevels(system, this.environment);
}
 
Example 8
Source File: ExampleTest.java    From eclair with Apache License 2.0 4 votes vote down vote up
@Bean
@Primary
public EclairLogger simpleLogger() {
    return new SimpleLogger(loggerFacadeFactory, LoggingSystem.get(SimpleLogger.class.getClassLoader()));
}
 
Example 9
Source File: SimpleLogger.java    From eclair with Apache License 2.0 4 votes vote down vote up
public SimpleLogger() {
    this(new Slf4JLoggerFacadeFactory(), LoggingSystem.get(SimpleLogger.class.getClassLoader()));
}
 
Example 10
Source File: LoggingSystemShutdownListener.java    From spring-cloud-commons with Apache License 2.0 4 votes vote down vote up
private void shutdownLogging() {
	LoggingSystem loggingSystem = LoggingSystem
			.get(ClassUtils.getDefaultClassLoader());
	loggingSystem.cleanUp();
	loggingSystem.beforeInitialize();
}