AbstractRequestLoggingFilter allows for dedicated shouldLog check in CommonsRequestLoggingFilter
Issue: SPR-12609
This commit is contained in:
parent
0ddf8dde12
commit
d4dac250a8
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -211,14 +211,15 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter
|
||||||
requestToUse = new ContentCachingRequestWrapper(request);
|
requestToUse = new ContentCachingRequestWrapper(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFirstRequest) {
|
boolean shouldLog = shouldLog(requestToUse);
|
||||||
|
if (shouldLog && isFirstRequest) {
|
||||||
beforeRequest(requestToUse, getBeforeMessage(requestToUse));
|
beforeRequest(requestToUse, getBeforeMessage(requestToUse));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
filterChain.doFilter(requestToUse, response);
|
filterChain.doFilter(requestToUse, response);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (!isAsyncStarted(requestToUse)) {
|
if (shouldLog && !isAsyncStarted(requestToUse)) {
|
||||||
afterRequest(requestToUse, getAfterMessage(requestToUse));
|
afterRequest(requestToUse, getAfterMessage(requestToUse));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,6 +290,22 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter
|
||||||
return msg.toString();
|
return msg.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether to call the {@link #beforeRequest}/{@link #afterRequest}
|
||||||
|
* methods for the current request, i.e. whether logging is currently active
|
||||||
|
* (and the log message is worth building).
|
||||||
|
* <p>The default implementation always returns {@code true}. Subclasses may
|
||||||
|
* override this with a log level check.
|
||||||
|
* @param request current HTTP request
|
||||||
|
* @return {@code true} if the before/after method should get called;
|
||||||
|
* {@code false} otherwise
|
||||||
|
* @since 4.1.5
|
||||||
|
*/
|
||||||
|
protected boolean shouldLog(HttpServletRequest request) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Concrete subclasses should implement this method to write a log message
|
* Concrete subclasses should implement this method to write a log message
|
||||||
* <i>before</i> the request is processed.
|
* <i>before</i> the request is processed.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2005 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -23,6 +23,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
* (and optionally the query string) to the Commons Log.
|
* (and optionally the query string) to the Commons Log.
|
||||||
*
|
*
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
|
* @author Juergen Hoeller
|
||||||
* @since 1.2.5
|
* @since 1.2.5
|
||||||
* @see #setIncludeQueryString
|
* @see #setIncludeQueryString
|
||||||
* @see #setBeforeMessagePrefix
|
* @see #setBeforeMessagePrefix
|
||||||
|
@ -33,14 +34,17 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
*/
|
*/
|
||||||
public class CommonsRequestLoggingFilter extends AbstractRequestLoggingFilter {
|
public class CommonsRequestLoggingFilter extends AbstractRequestLoggingFilter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean shouldLog(HttpServletRequest request) {
|
||||||
|
return logger.isDebugEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a log message before the request is processed.
|
* Writes a log message before the request is processed.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void beforeRequest(HttpServletRequest request, String message) {
|
protected void beforeRequest(HttpServletRequest request, String message) {
|
||||||
if (logger.isDebugEnabled()) {
|
logger.debug(message);
|
||||||
logger.debug(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,9 +52,7 @@ public class CommonsRequestLoggingFilter extends AbstractRequestLoggingFilter {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void afterRequest(HttpServletRequest request, String message) {
|
protected void afterRequest(HttpServletRequest request, String message) {
|
||||||
if (logger.isDebugEnabled()) {
|
logger.debug(message);
|
||||||
logger.debug(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue