pull/4069/head
Phillip Webb 9 years ago
parent cad2666522
commit acde5407e8

@ -142,7 +142,8 @@ public class MongoDataAutoConfiguration implements BeanClassLoaderAware {
context.setInitialEntitySet(getInitialEntitySet(beanFactory)); context.setInitialEntitySet(getInitialEntitySet(beanFactory));
Class<?> strategyClass = this.properties.getFieldNamingStrategy(); Class<?> strategyClass = this.properties.getFieldNamingStrategy();
if (strategyClass != null) { if (strategyClass != null) {
context.setFieldNamingStrategy((FieldNamingStrategy) BeanUtils.instantiate(strategyClass)); context.setFieldNamingStrategy((FieldNamingStrategy) BeanUtils
.instantiate(strategyClass));
} }
return context; return context;
} }

@ -86,8 +86,8 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
@Override @Override
protected String[] getStandardConfigLocations() { protected String[] getStandardConfigLocations() {
return new String[] { "logback-test.groovy", "logback-test.xml", "logback.groovy", return new String[] { "logback-test.groovy", "logback-test.xml",
"logback.xml" }; "logback.groovy", "logback.xml" };
} }
@Override @Override
@ -110,9 +110,8 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
LoggerContext context = getLoggerContext(); LoggerContext context = getLoggerContext();
stopAndReset(context); stopAndReset(context);
LogbackConfigurator configurator = new LogbackConfigurator(context); LogbackConfigurator configurator = new LogbackConfigurator(context);
context.putProperty("LOG_LEVEL_PATTERN", context.putProperty("LOG_LEVEL_PATTERN", initializationContext.getEnvironment()
initializationContext.getEnvironment().resolvePlaceholders( .resolvePlaceholders("${logging.pattern.level:${LOG_LEVEL_PATTERN:%5p}}"));
"${logging.pattern.level:${LOG_LEVEL_PATTERN:%5p}}"));
new DefaultLogbackConfiguration(initializationContext, logFile) new DefaultLogbackConfiguration(initializationContext, logFile)
.apply(configurator); .apply(configurator);
} }
@ -131,8 +130,8 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
ResourceUtils.getURL(location)); ResourceUtils.getURL(location));
} }
catch (Exception ex) { catch (Exception ex) {
throw new IllegalStateException( throw new IllegalStateException("Could not initialize Logback logging from "
"Could not initialize Logback logging from " + location, ex); + location, ex);
} }
List<Status> statuses = loggerContext.getStatusManager().getCopyOfStatusList(); List<Status> statuses = loggerContext.getStatusManager().getCopyOfStatusList();
StringBuilder errors = new StringBuilder(); StringBuilder errors = new StringBuilder();
@ -143,8 +142,8 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
} }
} }
if (errors.length() > 0) { if (errors.length() > 0) {
throw new IllegalStateException( throw new IllegalStateException("Logback configuration error "
"Logback configuration error " + "detected: \n" + errors); + "detected: \n" + errors);
} }
} }
@ -201,21 +200,20 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
private ch.qos.logback.classic.Logger getLogger(String name) { private ch.qos.logback.classic.Logger getLogger(String name) {
LoggerContext factory = getLoggerContext(); LoggerContext factory = getLoggerContext();
return factory return factory.getLogger(StringUtils.isEmpty(name) ? Logger.ROOT_LOGGER_NAME
.getLogger(StringUtils.isEmpty(name) ? Logger.ROOT_LOGGER_NAME : name); : name);
} }
private LoggerContext getLoggerContext() { private LoggerContext getLoggerContext() {
ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory(); ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory();
Assert.isInstanceOf(LoggerContext.class, factory, Assert.isInstanceOf(LoggerContext.class, factory, String.format(
String.format( "LoggerFactory is not a Logback LoggerContext but Logback is on "
"LoggerFactory is not a Logback LoggerContext but Logback is on " + "the classpath. Either remove Logback or the competing "
+ "the classpath. Either remove Logback or the competing " + "implementation (%s loaded from %s). If you are using "
+ "implementation (%s loaded from %s). If you are using " + "Weblogic you will need to add 'org.slf4j' to "
+ "Weblogic you will need to add 'org.slf4j' to " + "prefer-application-packages in WEB-INF/weblogic.xml",
+ "prefer-application-packages in WEB-INF/weblogic.xml", factory.getClass(), getLocation(factory)));
factory.getClass(), getLocation(factory)));
return (LoggerContext) factory; return (LoggerContext) factory;
} }

@ -16,16 +16,6 @@
package org.springframework.boot.logging.logback; package org.springframework.boot.logging.logback;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.util.logging.Handler; import java.util.logging.Handler;
@ -54,6 +44,16 @@ import org.springframework.util.StringUtils;
import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.LoggerContext;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link LogbackLoggingSystem}. * Tests for {@link LogbackLoggingSystem}.
* *

Loading…
Cancel
Save