Polish loggers

This commit is contained in:
Phillip Webb 2016-12-20 19:07:16 -08:00
parent e6097fb3e4
commit 38f7389eab
8 changed files with 41 additions and 35 deletions

View File

@ -38,7 +38,8 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
*/
class CloudFoundrySecurityInterceptor extends HandlerInterceptorAdapter {
protected final Log logger = LogFactory.getLog(getClass());
private static final Log logger = LogFactory
.getLog(CloudFoundrySecurityInterceptor.class);
private final TokenValidator tokenValidator;
@ -74,7 +75,7 @@ class CloudFoundrySecurityInterceptor extends HandlerInterceptorAdapter {
check(request, mvcEndpoint);
}
catch (CloudFoundryAuthorizationException ex) {
this.logger.error(ex);
logger.error(ex);
response.setContentType(MediaType.APPLICATION_JSON.toString());
response.getWriter()
.write("{\"security_error\":\"" + ex.getMessage() + "\"}");

View File

@ -18,9 +18,6 @@ package org.springframework.boot.autoconfigure.security.oauth2.resource;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
@ -43,8 +40,6 @@ import org.springframework.social.oauth2.AccessGrant;
*/
public class SpringSocialTokenServices implements ResourceServerTokenServices {
protected final Log logger = LogFactory.getLog(getClass());
private final OAuth2ConnectionFactory<?> connectionFactory;
private final String clientId;

View File

@ -81,20 +81,24 @@ public class AutoConfigurationReportLoggingInitializerTests {
given(this.log.isDebugEnabled()).willReturn(debug);
willAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return AutoConfigurationReportLoggingInitializerTests.this.debugLog
.add(String.valueOf(invocation.getArguments()[0]));
}
}).given(this.log).debug(anyObject());
given(this.log.isInfoEnabled()).willReturn(info);
willAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return AutoConfigurationReportLoggingInitializerTests.this.infoLog
.add(String.valueOf(invocation.getArguments()[0]));
}
}).given(this.log).info(anyObject());
LogFactory.releaseAll();

View File

@ -49,7 +49,7 @@ import org.springframework.util.Assert;
*/
public class ImageBanner implements Banner {
private static final Log log = LogFactory.getLog(ImageBanner.class);
private static final Log logger = LogFactory.getLog(ImageBanner.class);
private static final double[] RGB_WEIGHT = { 0.2126d, 0.7152d, 0.0722d };
@ -76,9 +76,9 @@ public class ImageBanner implements Banner {
printBanner(environment, out);
}
catch (Throwable ex) {
log.warn("Image banner not printable: " + this.image + " (" + ex.getClass()
logger.warn("Image banner not printable: " + this.image + " (" + ex.getClass()
+ ": '" + ex.getMessage() + "')");
log.debug("Image banner printing failure", ex);
logger.debug("Image banner printing failure", ex);
}
finally {
if (headless == null) {

View File

@ -58,7 +58,8 @@ public class PropertiesConfigurationFactory<T>
private static final char[] TARGET_NAME_DELIMITERS = { '_', '.' };
private final Log logger = LogFactory.getLog(getClass());
private static final Log logger = LogFactory
.getLog(PropertiesConfigurationFactory.class);
private boolean ignoreUnknownFields = true;
@ -228,8 +229,8 @@ public class PropertiesConfigurationFactory<T>
public void bindPropertiesToTarget() throws BindException {
Assert.state(this.propertySources != null, "PropertySources should not be null");
try {
if (this.logger.isTraceEnabled()) {
this.logger.trace("Property Sources: " + this.propertySources);
if (logger.isTraceEnabled()) {
logger.trace("Property Sources: " + this.propertySources);
}
this.hasBeenBound = true;
@ -239,8 +240,9 @@ public class PropertiesConfigurationFactory<T>
if (this.exceptionIfInvalid) {
throw ex;
}
this.logger.error("Failed to load Properties validation bean. "
+ "Your Properties may be invalid.", ex);
PropertiesConfigurationFactory.logger
.error("Failed to load Properties validation bean. "
+ "Your Properties may be invalid.", ex);
}
}
@ -340,10 +342,10 @@ public class PropertiesConfigurationFactory<T>
dataBinder.validate();
BindingResult errors = dataBinder.getBindingResult();
if (errors.hasErrors()) {
this.logger.error("Properties configuration failed validation");
logger.error("Properties configuration failed validation");
for (ObjectError error : errors.getAllErrors()) {
this.logger
.error(this.messageSource != null
logger.error(
this.messageSource != null
? this.messageSource.getMessage(error,
Locale.getDefault()) + " (" + error + ")"
: error);

View File

@ -52,7 +52,7 @@ import org.springframework.validation.Validator;
public class YamlConfigurationFactory<T>
implements FactoryBean<T>, MessageSourceAware, InitializingBean {
private final Log logger = LogFactory.getLog(getClass());
private static final Log logger = LogFactory.getLog(YamlConfigurationFactory.class);
private final Class<?> type;
@ -137,8 +137,8 @@ public class YamlConfigurationFactory<T>
Assert.state(this.yaml != null, "Yaml document should not be null: "
+ "either set it directly or set the resource to load it from");
try {
if (this.logger.isTraceEnabled()) {
this.logger.trace(String.format("Yaml document is %n%s", this.yaml));
if (logger.isTraceEnabled()) {
logger.trace(String.format("Yaml document is %n%s", this.yaml));
}
Constructor constructor = new YamlJavaBeanPropertyConstructor(this.type,
this.propertyAliases);
@ -151,7 +151,7 @@ public class YamlConfigurationFactory<T>
if (this.exceptionIfInvalid) {
throw ex;
}
this.logger.error("Failed to load YAML validation bean. "
logger.error("Failed to load YAML validation bean. "
+ "Your YAML file may be invalid.", ex);
}
}
@ -161,13 +161,9 @@ public class YamlConfigurationFactory<T>
"configuration");
this.validator.validate(this.configuration, errors);
if (errors.hasErrors()) {
this.logger.error("YAML configuration failed validation");
logger.error("YAML configuration failed validation");
for (ObjectError error : errors.getAllErrors()) {
this.logger
.error(this.messageSource != null
? this.messageSource.getMessage(error,
Locale.getDefault()) + " (" + error + ")"
: error);
logger.error(getErrorMessage(error));
}
if (this.exceptionIfInvalid) {
BindException summary = new BindException(errors);
@ -176,6 +172,14 @@ public class YamlConfigurationFactory<T>
}
}
private Object getErrorMessage(ObjectError error) {
if (this.messageSource != null) {
Locale locale = Locale.getDefault();
return this.messageSource.getMessage(error, locale) + " (" + error + ")";
}
return error;
}
@Override
public Class<?> getObjectType() {
if (this.configuration == null) {

View File

@ -48,7 +48,7 @@ import org.springframework.util.ReflectionUtils;
*/
public final class FailureAnalyzers {
private static final Log log = LogFactory.getLog(FailureAnalyzers.class);
private static final Log logger = LogFactory.getLog(FailureAnalyzers.class);
private final ClassLoader classLoader;
@ -82,7 +82,7 @@ public final class FailureAnalyzers {
analyzers.add((FailureAnalyzer) constructor.newInstance());
}
catch (Throwable ex) {
log.trace("Failed to load " + analyzerName, ex);
logger.trace("Failed to load " + analyzerName, ex);
}
}
AnnotationAwareOrderComparator.sort(analyzers);

View File

@ -42,17 +42,17 @@ public final class ClasspathLoggingApplicationListener
private static final int ORDER = LoggingApplicationListener.DEFAULT_ORDER + 1;
private final Log logger = LogFactory.getLog(getClass());
private static final Log logger = LogFactory
.getLog(ClasspathLoggingApplicationListener.class);
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (this.logger.isDebugEnabled()) {
if (logger.isDebugEnabled()) {
if (event instanceof ApplicationEnvironmentPreparedEvent) {
this.logger
.debug("Application started with classpath: " + getClasspath());
logger.debug("Application started with classpath: " + getClasspath());
}
else if (event instanceof ApplicationFailedEvent) {
this.logger.debug(
logger.debug(
"Application failed to start with classpath: " + getClasspath());
}
}