From 27a81e1463ffa5ba90190cc4855ff4d8e96acb1b Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 13 Jan 2016 16:22:35 +0000 Subject: [PATCH] Complete static final logger changes that were started in ec2f33f9 This commit completes the changes to consistently used static final fields for Log instances that were started in ec2f33f9. Specifically it: - Removes this. when accessing logger fields that are now static - Renames some fields from log to logger - Makes some logger fields static See gh-4784 --- .../actuate/trace/WebRequestTraceFilter.java | 8 ++--- .../jackson/JacksonAutoConfiguration.java | 9 ++--- .../ArtemisEmbeddedConfigurationFactory.java | 7 ++-- .../HornetQEmbeddedConfigurationFactory.java | 7 ++-- .../boot/loader/PropertiesLauncher.java | 33 +++++++++---------- .../springframework/boot/ResourceBanner.java | 6 ++-- .../boot/SpringApplication.java | 20 +++++------ .../ServletContextInitializerBeans.java | 17 +++++----- 8 files changed, 55 insertions(+), 52 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/WebRequestTraceFilter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/WebRequestTraceFilter.java index 3d047836394..0e47397833f 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/WebRequestTraceFilter.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/WebRequestTraceFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -187,11 +187,11 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order } private void logTrace(HttpServletRequest request, Map trace) { - if (this.logger.isTraceEnabled()) { - this.logger.trace("Processing request " + request.getMethod() + " " + if (logger.isTraceEnabled()) { + logger.trace("Processing request " + request.getMethod() + " " + request.getRequestURI()); if (this.dumpRequests) { - this.logger.trace("Headers: " + trace.get("headers")); + logger.trace("Headers: " + trace.get("headers")); } } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java index 099780e8d85..8318c3afb9c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -94,7 +94,8 @@ public class JacksonAutoConfiguration { DateTimeSerializer.class, JacksonJodaDateFormat.class }) static class JodaDateTimeJacksonConfiguration { - private static final Log log = LogFactory.getLog(JodaDateTimeJacksonConfiguration.class); + private static final Log logger = LogFactory + .getLog(JodaDateTimeJacksonConfiguration.class); @Autowired private JacksonProperties jacksonProperties; @@ -123,8 +124,8 @@ public class JacksonAutoConfiguration { .withZoneUTC()); } catch (IllegalArgumentException ex) { - if (this.log.isWarnEnabled()) { - this.log.warn("spring.jackson.date-format could not be used to " + if (logger.isWarnEnabled()) { + logger.warn("spring.jackson.date-format could not be used to " + "configure formatting of Joda's DateTime. You may want " + "to configure spring.jackson.joda-date-time-format as " + "well."); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisEmbeddedConfigurationFactory.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisEmbeddedConfigurationFactory.java index 6c256ecdf40..e10effde04b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisEmbeddedConfigurationFactory.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisEmbeddedConfigurationFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,8 @@ import org.apache.commons.logging.LogFactory; */ class ArtemisEmbeddedConfigurationFactory { - private static final Log logger = LogFactory.getLog(ArtemisEmbeddedConfigurationFactory.class); + private static final Log logger = LogFactory + .getLog(ArtemisEmbeddedConfigurationFactory.class); private final ArtemisProperties.Embedded properties; @@ -60,7 +61,7 @@ class ArtemisEmbeddedConfigurationFactory { this.properties.generateTransportParameters()); configuration.getAcceptorConfigurations().add(transportConfiguration); if (this.properties.isDefaultClusterPassword()) { - this.logger.debug("Using default Artemis cluster password: " + logger.debug("Using default Artemis cluster password: " + this.properties.getClusterPassword()); } configuration.setClusterPassword(this.properties.getClusterPassword()); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQEmbeddedConfigurationFactory.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQEmbeddedConfigurationFactory.java index 4d1cfee394b..79d27b89df9 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQEmbeddedConfigurationFactory.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQEmbeddedConfigurationFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,8 @@ import org.springframework.boot.autoconfigure.jms.hornetq.HornetQProperties.Embe */ class HornetQEmbeddedConfigurationFactory { - private static final Log logger = LogFactory.getLog(HornetQEmbeddedConfigurationFactory.class); + private static final Log logger = LogFactory + .getLog(HornetQEmbeddedConfigurationFactory.class); private final Embedded properties; @@ -69,7 +70,7 @@ class HornetQEmbeddedConfigurationFactory { // HORNETQ-1143 if (this.properties.isDefaultClusterPassword()) { - this.logger.debug("Using default HornetQ cluster password: " + logger.debug("Using default HornetQ cluster password: " + this.properties.getClusterPassword()); } diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java index 971b59056e6..c93bbbca73d 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -139,7 +139,7 @@ public class PropertiesLauncher extends Launcher { public PropertiesLauncher() { if (!isDebug()) { - this.logger.setLevel(Level.SEVERE); + logger.setLevel(Level.SEVERE); } try { this.home = getHomeDirectory(); @@ -183,7 +183,7 @@ public class PropertiesLauncher extends Launcher { InputStream resource = getResource(config); if (resource != null) { - this.logger.info("Found: " + config); + logger.info("Found: " + config); try { this.properties.load(resource); } @@ -201,7 +201,7 @@ public class PropertiesLauncher extends Launcher { if (SystemPropertyUtils .resolvePlaceholders("${" + SET_SYSTEM_PROPERTIES + ":false}") .equals("true")) { - this.logger.info("Adding resolved properties to System properties"); + logger.info("Adding resolved properties to System properties"); for (Object key : Collections.list(this.properties.propertyNames())) { String value = this.properties.getProperty((String) key); System.setProperty((String) key, value); @@ -209,7 +209,7 @@ public class PropertiesLauncher extends Launcher { } } else { - this.logger.info("Not found: " + config); + logger.info("Not found: " + config); } } @@ -244,13 +244,13 @@ public class PropertiesLauncher extends Launcher { config = config.substring(1); } config = "/" + config; - this.logger.fine("Trying classpath: " + config); + logger.fine("Trying classpath: " + config); return getClass().getResourceAsStream(config); } private InputStream getFileResource(String config) throws Exception { File file = new File(config); - this.logger.fine("Trying file: " + config); + logger.fine("Trying file: " + config); if (file.canRead()) { return new FileInputStream(file); } @@ -310,7 +310,7 @@ public class PropertiesLauncher extends Launcher { this.paths = parsePathsProperty( SystemPropertyUtils.resolvePlaceholders(path)); } - this.logger.info("Nested archive paths: " + this.paths); + logger.info("Nested archive paths: " + this.paths); } private List parsePathsProperty(String commaSeparatedPaths) { @@ -358,7 +358,7 @@ public class PropertiesLauncher extends Launcher { String customLoaderClassName = getProperty("loader.classLoader"); if (customLoaderClassName != null) { loader = wrapWithCustomClassLoader(loader, customLoaderClassName); - this.logger.info("Using custom class loader: " + customLoaderClassName); + logger.info("Using custom class loader: " + customLoaderClassName); } return loader; } @@ -401,14 +401,14 @@ public class PropertiesLauncher extends Launcher { String property = SystemPropertyUtils.getProperty(propertyKey); if (property != null) { String value = SystemPropertyUtils.resolvePlaceholders(property); - this.logger.fine("Property '" + propertyKey + "' from environment: " + value); + logger.fine("Property '" + propertyKey + "' from environment: " + value); return value; } if (this.properties.containsKey(propertyKey)) { String value = SystemPropertyUtils .resolvePlaceholders(this.properties.getProperty(propertyKey)); - this.logger.fine("Property '" + propertyKey + "' from properties: " + value); + logger.fine("Property '" + propertyKey + "' from properties: " + value); return value; } @@ -417,7 +417,7 @@ public class PropertiesLauncher extends Launcher { Manifest manifest = new ExplodedArchive(this.home, false).getManifest(); if (manifest != null) { String value = manifest.getMainAttributes().getValue(manifestKey); - this.logger.fine("Property '" + manifestKey + logger.fine("Property '" + manifestKey + "' from home directory manifest: " + value); return value; } @@ -431,7 +431,7 @@ public class PropertiesLauncher extends Launcher { if (manifest != null) { String value = manifest.getMainAttributes().getValue(manifestKey); if (value != null) { - this.logger.fine( + logger.fine( "Property '" + manifestKey + "' from archive manifest: " + value); return value; } @@ -462,20 +462,19 @@ public class PropertiesLauncher extends Launcher { file = new File(this.home, root); } if (file.isDirectory()) { - this.logger.info("Adding classpath entries from " + file); + logger.info("Adding classpath entries from " + file); Archive archive = new ExplodedArchive(file, false); lib.add(archive); } Archive archive = getArchive(file); if (archive != null) { - this.logger.info( + logger.info( "Adding classpath entries from archive " + archive.getUrl() + root); lib.add(archive); } Archive nested = getNestedArchive(root); if (nested != null) { - this.logger.info( - "Adding classpath entries from nested " + nested.getUrl() + root); + logger.info("Adding classpath entries from nested " + nested.getUrl() + root); lib.add(nested); } return lib; diff --git a/spring-boot/src/main/java/org/springframework/boot/ResourceBanner.java b/spring-boot/src/main/java/org/springframework/boot/ResourceBanner.java index 901d3dbfd02..6eab88af177 100644 --- a/spring-boot/src/main/java/org/springframework/boot/ResourceBanner.java +++ b/spring-boot/src/main/java/org/springframework/boot/ResourceBanner.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ import org.springframework.util.StreamUtils; */ public class ResourceBanner implements Banner { - private static final Log log = LogFactory.getLog(ResourceBanner.class); + private static final Log logger = LogFactory.getLog(ResourceBanner.class); private Resource resource; @@ -71,7 +71,7 @@ public class ResourceBanner implements Banner { out.println(banner); } catch (Exception ex) { - log.warn("Banner not printable: " + this.resource + " (" + ex.getClass() + logger.warn("Banner not printable: " + this.resource + " (" + ex.getClass() + ": '" + ex.getMessage() + "')", ex); } } diff --git a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index 25a14501156..f2428efab2c 100644 --- a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -188,7 +188,7 @@ public class SpringApplication { SERVLET_ENVIRONMENT_SOURCE_NAMES = Collections.unmodifiableSet(names); } - private final Log log = LogFactory.getLog(getClass()); + private static final Log logger = LogFactory.getLog(SpringApplication.class); private final Set sources = new LinkedHashSet(); @@ -377,7 +377,7 @@ public class SpringApplication { private SpringApplicationRunListeners getRunListeners(String[] args) { Class[] types = new Class[] { SpringApplication.class, String[].class }; - return new SpringApplicationRunListeners(this.log, getSpringFactoriesInstances( + return new SpringApplicationRunListeners(logger, getSpringFactoriesInstances( SpringApplicationRunListener.class, types, this, args)); } @@ -538,10 +538,10 @@ public class SpringApplication { Banner selectedBanner = selectBanner(environment); if (this.bannerMode == Banner.Mode.LOG) { try { - this.log.info(createStringFromBanner(selectedBanner, environment)); + logger.info(createStringFromBanner(selectedBanner, environment)); } catch (UnsupportedEncodingException ex) { - this.log.warn("Failed to create String for banner", ex); + logger.warn("Failed to create String for banner", ex); } } else { @@ -679,7 +679,7 @@ public class SpringApplication { */ protected Log getApplicationLog() { if (this.mainApplicationClass == null) { - return this.log; + return logger; } return LogFactory.getLog(this.mainApplicationClass); } @@ -690,8 +690,8 @@ public class SpringApplication { * @param sources the sources to load */ protected void load(ApplicationContext context, Object[] sources) { - if (this.log.isDebugEnabled()) { - this.log.debug( + if (logger.isDebugEnabled()) { + logger.debug( "Loading source " + StringUtils.arrayToCommaDelimitedString(sources)); } BeanDefinitionLoader loader = createBeanDefinitionLoader( @@ -823,8 +823,8 @@ public class SpringApplication { private void handleRunFailure(ConfigurableApplicationContext context, SpringApplicationRunListeners listeners, Throwable exception) { - if (this.log.isErrorEnabled()) { - this.log.error("Application startup failed", exception); + if (logger.isErrorEnabled()) { + logger.error("Application startup failed", exception); registerLoggedException(exception); } try { @@ -839,7 +839,7 @@ public class SpringApplication { } } catch (Exception ex) { - this.log.warn("Unable to close ApplicationContext", ex); + logger.warn("Unable to close ApplicationContext", ex); } ReflectionUtils.rethrowRuntimeException(exception); } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletContextInitializerBeans.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletContextInitializerBeans.java index 826acb484c2..7d506d352aa 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletContextInitializerBeans.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletContextInitializerBeans.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,7 +61,8 @@ class ServletContextInitializerBeans static final String DISPATCHER_SERVLET_NAME = "dispatcherServlet"; - private final Log log = LogFactory.getLog(getClass()); + private static final Log logger = LogFactory + .getLog(ServletContextInitializerBeans.class); /** * Seen bean instances or bean names. @@ -131,12 +132,12 @@ class ServletContextInitializerBeans // Mark the underlying source as seen in case it wraps an existing bean this.seen.add(source); } - if (this.log.isDebugEnabled()) { + if (ServletContextInitializerBeans.logger.isDebugEnabled()) { String resourceDescription = getResourceDescription(beanName, beanFactory); int order = getOrder(initializer); - this.log.debug("Added existing " + type.getSimpleName() - + " initializer bean '" + beanName + "'; order=" + order - + ", resource=" + resourceDescription); + ServletContextInitializerBeans.logger.debug("Added existing " + + type.getSimpleName() + " initializer bean '" + beanName + + "'; order=" + order + ", resource=" + resourceDescription); } } @@ -189,8 +190,8 @@ class ServletContextInitializerBeans registration.setName(beanName); registration.setOrder(order); this.initializers.add(type, registration); - if (this.log.isDebugEnabled()) { - this.log.debug( + if (ServletContextInitializerBeans.logger.isDebugEnabled()) { + ServletContextInitializerBeans.logger.debug( "Created " + type.getSimpleName() + " initializer for bean '" + beanName + "'; order=" + order + ", resource=" + getResourceDescription(beanName, beanFactory));