Avoid double logging config init + support for slf4j-log4j.

This commit is contained in:
johnou
2013-12-16 12:33:54 +01:00
committed by Dave Syer
parent b72002142d
commit e9c649dfb2
2 changed files with 11 additions and 1 deletions

View File

@@ -42,7 +42,6 @@ public abstract class AbstractLoggingSystem extends LoggingSystem {
@Override
public void beforeInitialize() {
initializeWithSensibleDefaults();
}
@Override

View File

@@ -23,10 +23,12 @@ import java.util.Map;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.slf4j.bridge.SLF4JBridgeHandler;
import org.springframework.boot.logging.AbstractLoggingSystem;
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.Log4jConfigurer;
import org.springframework.util.StringUtils;
@@ -54,6 +56,15 @@ public class Log4JLoggingSystem extends AbstractLoggingSystem {
super(classLoader, "log4j.xml", "log4j.properties");
}
@Override
public void beforeInitialize() {
super.beforeInitialize();
if (ClassUtils.isPresent("org.slf4j.bridge.SLF4JBridgeHandler", getClassLoader())) {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
}
}
@Override
public void initialize(String configLocation) {
Assert.notNull(configLocation, "ConfigLocation must not be null");