|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2012 the original author or authors. |
|
|
|
* Copyright 2002-2017 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. |
|
|
|
@ -58,6 +58,12 @@ public abstract class AbstractTraceInterceptor implements MethodInterceptor, Ser |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private boolean hideProxyClassNames = false; |
|
|
|
private boolean hideProxyClassNames = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Indicates whether to pass an exception to the logger. |
|
|
|
|
|
|
|
* @see #writeToLog(Log, String, Throwable) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private boolean logExceptionStackTrace = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set whether to use a dynamic logger or a static logger. |
|
|
|
* Set whether to use a dynamic logger or a static logger. |
|
|
|
@ -98,6 +104,17 @@ public abstract class AbstractTraceInterceptor implements MethodInterceptor, Ser |
|
|
|
this.hideProxyClassNames = hideProxyClassNames; |
|
|
|
this.hideProxyClassNames = hideProxyClassNames; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Set whether to pass an exception to the logger, suggesting inclusion |
|
|
|
|
|
|
|
* of its stack trace into the log. Default is "true"; set this to "false" |
|
|
|
|
|
|
|
* in order to reduce the log output to just the trace message (which may |
|
|
|
|
|
|
|
* include the exception class name and exception message, if applicable). |
|
|
|
|
|
|
|
* @since 4.3.10 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void setLogExceptionStackTrace(boolean logExceptionStackTrace) { |
|
|
|
|
|
|
|
this.logExceptionStackTrace = logExceptionStackTrace; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Determines whether or not logging is enabled for the particular {@code MethodInvocation}. |
|
|
|
* Determines whether or not logging is enabled for the particular {@code MethodInvocation}. |
|
|
|
@ -171,6 +188,40 @@ public abstract class AbstractTraceInterceptor implements MethodInterceptor, Ser |
|
|
|
return logger.isTraceEnabled(); |
|
|
|
return logger.isTraceEnabled(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Write the supplied trace message to the supplied {@code Log} instance. |
|
|
|
|
|
|
|
* <p>To be called by {@link #invokeUnderTrace} for enter/exit messages. |
|
|
|
|
|
|
|
* <p>Delegates to {@link #writeToLog(Log, String, Throwable)} as the |
|
|
|
|
|
|
|
* ultimate delegate that controls the underlying logger invocation. |
|
|
|
|
|
|
|
* @since 4.3.10 |
|
|
|
|
|
|
|
* @see #writeToLog(Log, String, Throwable) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected void writeToLog(Log logger, String message) { |
|
|
|
|
|
|
|
writeToLog(logger, message, null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Write the supplied trace message and {@link Throwable} to the |
|
|
|
|
|
|
|
* supplied {@code Log} instance. |
|
|
|
|
|
|
|
* <p>To be called by {@link #invokeUnderTrace} for enter/exit outcomes, |
|
|
|
|
|
|
|
* potentially including an exception. Note that an exception's stack trace |
|
|
|
|
|
|
|
* won't get logged when {@link #setLogExceptionStackTrace} is "false". |
|
|
|
|
|
|
|
* <p>By default messages are written at {@code TRACE} level. Subclasses |
|
|
|
|
|
|
|
* can override this method to control which level the message is written |
|
|
|
|
|
|
|
* at, typically also overriding {@link #isLogEnabled} accordingly. |
|
|
|
|
|
|
|
* @since 4.3.10 |
|
|
|
|
|
|
|
* @see #setLogExceptionStackTrace |
|
|
|
|
|
|
|
* @see #isLogEnabled |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected void writeToLog(Log logger, String message, Throwable ex) { |
|
|
|
|
|
|
|
if (ex != null && this.logExceptionStackTrace) { |
|
|
|
|
|
|
|
logger.trace(message, ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
logger.trace(message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Subclasses must override this method to perform any tracing around the |
|
|
|
* Subclasses must override this method to perform any tracing around the |
|
|
|
@ -180,13 +231,15 @@ public abstract class AbstractTraceInterceptor implements MethodInterceptor, Ser |
|
|
|
* <p>By default, the passed-in {@code Log} instance will have log level |
|
|
|
* <p>By default, the passed-in {@code Log} instance will have log level |
|
|
|
* "trace" enabled. Subclasses do not have to check for this again, unless |
|
|
|
* "trace" enabled. Subclasses do not have to check for this again, unless |
|
|
|
* they overwrite the {@code isInterceptorEnabled} method to modify |
|
|
|
* they overwrite the {@code isInterceptorEnabled} method to modify |
|
|
|
* the default behavior. |
|
|
|
* the default behavior, and may delegate to {@code writeToLog} for actual |
|
|
|
|
|
|
|
* messages to be written. |
|
|
|
* @param logger the {@code Log} to write trace messages to |
|
|
|
* @param logger the {@code Log} to write trace messages to |
|
|
|
* @return the result of the call to {@code MethodInvocation.proceed()} |
|
|
|
* @return the result of the call to {@code MethodInvocation.proceed()} |
|
|
|
* @throws Throwable if the call to {@code MethodInvocation.proceed()} |
|
|
|
* @throws Throwable if the call to {@code MethodInvocation.proceed()} |
|
|
|
* encountered any errors |
|
|
|
* encountered any errors |
|
|
|
* @see #isInterceptorEnabled |
|
|
|
|
|
|
|
* @see #isLogEnabled |
|
|
|
* @see #isLogEnabled |
|
|
|
|
|
|
|
* @see #writeToLog(Log, String) |
|
|
|
|
|
|
|
* @see #writeToLog(Log, String, Throwable) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected abstract Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable; |
|
|
|
protected abstract Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable; |
|
|
|
|
|
|
|
|
|
|
|
|