Revised log levels: less WARN and INFO, fine-tuned DEBUG vs TRACE

Issue: SPR-16946
This commit is contained in:
Juergen Hoeller
2018-07-20 15:05:13 +02:00
parent a410d90439
commit 9a43d2ec20
99 changed files with 461 additions and 486 deletions

View File

@@ -46,8 +46,8 @@ import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
* Adapt {@link HttpHandler} to an {@link HttpServlet} using Servlet Async
* support and Servlet 3.1 non-blocking I/O.
* Adapt {@link HttpHandler} to an {@link HttpServlet} using Servlet Async support
* and Servlet 3.1 non-blocking I/O.
*
* @author Arjen Poutsma
* @author Rossen Stoyanchev
@@ -140,8 +140,8 @@ public class ServletHttpHandlerAdapter implements Servlet {
}
if (mapping.endsWith("/*")) {
String path = mapping.substring(0, mapping.length() - 2);
if (!path.isEmpty()) {
logger.info("Found servlet mapping prefix '" + path + "' for '" + name + "'");
if (!path.isEmpty() && logger.isDebugEnabled()) {
logger.debug("Found servlet mapping prefix '" + path + "' for '" + name + "'");
}
return path;
}

View File

@@ -264,8 +264,8 @@ public class ContextLoader {
"check whether you have multiple ContextLoader* definitions in your web.xml!");
}
Log logger = LogFactory.getLog(ContextLoader.class);
servletContext.log("Initializing Spring root WebApplicationContext");
Log logger = LogFactory.getLog(ContextLoader.class);
if (logger.isInfoEnabled()) {
logger.info("Root WebApplicationContext: initialization started");
}
@@ -301,10 +301,6 @@ public class ContextLoader {
currentContextPerThread.put(ccl, this.context);
}
if (logger.isDebugEnabled()) {
logger.debug("Published root WebApplicationContext as ServletContext attribute with name [" +
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE + "]");
}
if (logger.isInfoEnabled()) {
long elapsedTime = System.currentTimeMillis() - startTime;
logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms");
@@ -312,16 +308,11 @@ public class ContextLoader {
return this.context;
}
catch (RuntimeException ex) {
catch (RuntimeException | Error ex) {
logger.error("Context initialization failed", ex);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
throw ex;
}
catch (Error err) {
logger.error("Context initialization failed", err);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, err);
throw err;
}
}
/**

View File

@@ -209,16 +209,16 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe
}
if (!this.annotatedClasses.isEmpty()) {
if (logger.isInfoEnabled()) {
logger.info("Registering annotated classes: [" +
if (logger.isDebugEnabled()) {
logger.debug("Registering annotated classes: [" +
StringUtils.collectionToCommaDelimitedString(this.annotatedClasses) + "]");
}
reader.register(ClassUtils.toClassArray(this.annotatedClasses));
}
if (!this.basePackages.isEmpty()) {
if (logger.isInfoEnabled()) {
logger.info("Scanning base packages: [" +
if (logger.isDebugEnabled()) {
logger.debug("Scanning base packages: [" +
StringUtils.collectionToCommaDelimitedString(this.basePackages) + "]");
}
scanner.scan(StringUtils.toStringArray(this.basePackages));
@@ -229,24 +229,19 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe
for (String configLocation : configLocations) {
try {
Class<?> clazz = ClassUtils.forName(configLocation, getClassLoader());
if (logger.isInfoEnabled()) {
logger.info("Successfully resolved class for [" + configLocation + "]");
if (logger.isTraceEnabled()) {
logger.trace("Successfully resolved class for [" + configLocation + "]");
}
reader.register(clazz);
}
catch (ClassNotFoundException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Could not load class for config location [" + configLocation +
if (logger.isTraceEnabled()) {
logger.trace("Could not load class for config location [" + configLocation +
"] - trying package scan. " + ex);
}
int count = scanner.scan(configLocation);
if (logger.isInfoEnabled()) {
if (count == 0) {
logger.info("No annotated classes found for specified class/package [" + configLocation + "]");
}
else {
logger.info("Found " + count + " annotated classes in package [" + configLocation + "]");
}
if (count == 0 && logger.isDebugEnabled()) {
logger.debug("No annotated classes found for specified class/package [" + configLocation + "]");
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -70,14 +70,14 @@ public class ServletContextAttributeExporter implements ServletContextAware {
if (this.attributes != null) {
for (Map.Entry<String, Object> entry : this.attributes.entrySet()) {
String attributeName = entry.getKey();
if (logger.isWarnEnabled()) {
if (logger.isDebugEnabled()) {
if (servletContext.getAttribute(attributeName) != null) {
logger.warn("Replacing existing ServletContext attribute with name '" + attributeName + "'");
logger.debug("Replacing existing ServletContext attribute with name '" + attributeName + "'");
}
}
servletContext.setAttribute(attributeName, entry.getValue());
if (logger.isInfoEnabled()) {
logger.info("Exported ServletContext attribute with name '" + attributeName + "'");
if (logger.isTraceEnabled()) {
logger.trace("Exported ServletContext attribute with name '" + attributeName + "'");
}
}
}