spring-framework / org.springframework.aop.interceptor / AbstractTraceInterceptor

AbstractTraceInterceptor

abstract class AbstractTraceInterceptor : MethodInterceptor, Serializable

Base MethodInterceptor implementation for tracing.

By default, log messages are written to the log for the interceptor class, not the class which is being intercepted. Setting the useDynamicLogger bean property to true causes all log messages to be written to the Log for the target class being intercepted.

Subclasses must implement the invokeUnderTrace method, which is invoked by this class ONLY when a particular invocation SHOULD be traced. Subclasses should write to the Log instance provided.

Author
Rob Harrop

Author
Juergen Hoeller

Since
1.2

See Also
#setUseDynamicLogger#invokeUnderTrace(org.aopalliance.intercept.MethodInvocation, org.apache.commons.logging.Log)

Constructors

<init>

AbstractTraceInterceptor()

Base MethodInterceptor implementation for tracing.

By default, log messages are written to the log for the interceptor class, not the class which is being intercepted. Setting the useDynamicLogger bean property to true causes all log messages to be written to the Log for the target class being intercepted.

Subclasses must implement the invokeUnderTrace method, which is invoked by this class ONLY when a particular invocation SHOULD be traced. Subclasses should write to the Log instance provided.

Functions

invoke

open fun invoke(invocation: MethodInvocation): Any

Determines whether or not logging is enabled for the particular MethodInvocation. If not, the method invocation proceeds as normal, otherwise the method invocation is passed to the invokeUnderTrace method for handling.

setHideProxyClassNames

open fun setHideProxyClassNames(hideProxyClassNames: Boolean): Unit

Set to "true" to have dynamic loggers hide proxy class names wherever possible. Default is "false".

setLogExceptionStackTrace

open fun setLogExceptionStackTrace(logExceptionStackTrace: Boolean): Unit

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).

setLoggerName

open fun setLoggerName(loggerName: String): Unit

Set the name of the logger to use. The name will be passed to the underlying logger implementation through Commons Logging, getting interpreted as log category according to the logger's configuration.

This can be specified to not log into the category of a class (whether this interceptor's class or the class getting called) but rather into a specific named category.

NOTE: Specify either this property or "useDynamicLogger", not both.

setUseDynamicLogger

open fun setUseDynamicLogger(useDynamicLogger: Boolean): Unit

Set whether to use a dynamic logger or a static logger. Default is a static logger for this trace interceptor.

Used to determine which Log instance should be used to write log messages for a particular method invocation: a dynamic one for the Class getting called, or a static one for the Class of the trace interceptor.

NOTE: Specify either this property or "loggerName", not both.

Inheritors

CustomizableTraceInterceptor

open class CustomizableTraceInterceptor : AbstractTraceInterceptor

MethodInterceptor implementation that allows for highly customizable method-level tracing, using placeholders.

Trace messages are written on method entry, and if the method invocation succeeds on method exit. If an invocation results in an exception, then an exception message is written. The contents of these trace messages is fully customizable and special placeholders are available to allow you to include runtime information in your log messages. The placeholders available are:

  • $[methodName] - replaced with the name of the method being invoked
  • $[targetClassName] - replaced with the name of the class that is the target of the invocation
  • $[targetClassShortName] - replaced with the short name of the class that is the target of the invocation
  • $[returnValue] - replaced with the value returned by the invocation
  • $[argumentTypes] - replaced with a comma-separated list of the short class names of the method arguments
  • $[arguments] - replaced with a comma-separated list of the String representation of the method arguments
  • $[exception] - replaced with the String representation of any Throwable raised during the invocation
  • $[invocationTime] - replaced with the time, in milliseconds, taken by the method invocation

There are restrictions on which placeholders can be used in which messages: see the individual message properties for details on the valid placeholders.