Browse Source

Merge branch '1.5.x'

pull/6223/merge
Phillip Webb 9 years ago
parent
commit
90fb309f1e
  1. 36
      spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringBootConfigurationFactory.java
  2. 1
      spring-boot/src/main/resources/log4j2.springboot

36
spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringBootConfigurationFactory.java

@ -16,8 +16,6 @@
package org.springframework.boot.logging.log4j2; package org.springframework.boot.logging.log4j2;
import java.net.URI;
import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory; import org.apache.logging.log4j.core.config.ConfigurationFactory;
@ -26,42 +24,38 @@ import org.apache.logging.log4j.core.config.DefaultConfiguration;
import org.apache.logging.log4j.core.config.Order; import org.apache.logging.log4j.core.config.Order;
import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.springframework.boot.logging.LoggingSystem;
/** /**
* Spring Boot {@link ConfigurationFactory} that prevents logger warnings from being * Spring Boot {@link ConfigurationFactory} that prevents logger warnings from being
* printed when the application first starts. * printed when the application first starts. This factory is ordered last and is
* triggered by a {@code log4j2.springboot} classpath resource (which is bundled in this
* jar). If the {@link Log4J2LoggingSystem} is active, a {@link DefaultConfiguration} is
* returned with the expectation that the system will later re-initialize Log4J2 with the
* correct configuration file.
* *
* @author Phillip Webb * @author Phillip Webb
* @since 1.5.0 * @since 1.5.0
*/ */
@Plugin(name = "SpringBootConfigurationFactory", category = ConfigurationFactory.CATEGORY) @Plugin(name = "SpringBootConfigurationFactory", category = ConfigurationFactory.CATEGORY)
@Order(4) // Order behind XmlConfigurationFactory @Order(0)
public class SpringBootConfigurationFactory extends ConfigurationFactory { public class SpringBootConfigurationFactory extends ConfigurationFactory {
private static final String[] ALL_TYPES = { "*" }; private static final String[] TYPES = { ".springboot" };
@Override @Override
protected String[] getSupportedTypes() { protected String[] getSupportedTypes() {
return ALL_TYPES; return TYPES;
}
@Override
public Configuration getConfiguration(LoggerContext loggerContext, String name,
URI configLocation) {
if (configLocation == null) {
return new DefaultConfiguration();
}
return null;
}
@Override
public Configuration getConfiguration(LoggerContext loggerContext, String name,
URI configLocation, ClassLoader loader) {
return null;
} }
@Override @Override
public Configuration getConfiguration(LoggerContext loggerContext, public Configuration getConfiguration(LoggerContext loggerContext,
ConfigurationSource source) { ConfigurationSource source) {
if (source != null && source != ConfigurationSource.NULL_SOURCE) {
if (LoggingSystem.get(loggerContext.getClass().getClassLoader()) != null) {
return new DefaultConfiguration();
}
}
return null; return null;
} }

1
spring-boot/src/main/resources/log4j2.springboot

@ -0,0 +1 @@
See SpringBootConfigurationFactory
Loading…
Cancel
Save