Browse Source

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

pull/165/merge
johnou 12 years ago committed by Dave Syer
parent
commit
e9c649dfb2
  1. 1
      spring-boot/src/main/java/org/springframework/boot/logging/AbstractLoggingSystem.java
  2. 11
      spring-boot/src/main/java/org/springframework/boot/logging/log4j/Log4JLoggingSystem.java

1
spring-boot/src/main/java/org/springframework/boot/logging/AbstractLoggingSystem.java

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

11
spring-boot/src/main/java/org/springframework/boot/logging/log4j/Log4JLoggingSystem.java

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

Loading…
Cancel
Save