类 AbstractTraceInterceptor

java.lang.Object
infra.aop.interceptor.AbstractTraceInterceptor
所有已实现的接口:
Serializable, Advice, Interceptor, MethodInterceptor
直接已知子类:
AbstractMonitoringInterceptor, CustomizableTraceInterceptor, SimpleTraceInterceptor

public abstract class AbstractTraceInterceptor extends Object implements 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 Logger 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 Logger instance provided.

从以下版本开始:
3.0
作者:
Rob Harrop, Juergen Hoeller, TODAY
另请参阅:
  • 字段详细资料

    • defaultLogger

      protected transient infra.logging.Logger defaultLogger
    • hideProxyClassNames

      private boolean hideProxyClassNames
      Indicates whether or not proxy class names should be hidden when using dynamic loggers.
      另请参阅:
    • logExceptionStackTrace

      private boolean logExceptionStackTrace
      Indicates whether to pass an exception to the logger.
      另请参阅:
  • 构造器详细资料

    • AbstractTraceInterceptor

      public AbstractTraceInterceptor()
  • 方法详细资料

    • setUseDynamicLogger

      public void setUseDynamicLogger(boolean useDynamicLogger)
      Set whether to use a dynamic logger or a static logger. Default is a static logger for this trace interceptor.

      Used to determine which Logger 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.

      另请参阅:
    • setLoggerName

      public void setLoggerName(String loggerName)
      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.

      另请参阅:
    • setHideProxyClassNames

      public void setHideProxyClassNames(boolean hideProxyClassNames)
      Set to "true" to have dynamic loggers hide proxy class names wherever possible. Default is "false".
    • setLogExceptionStackTrace

      public void setLogExceptionStackTrace(boolean logExceptionStackTrace)
      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).
    • invoke

      public Object invoke(MethodInvocation invocation) throws Throwable
      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.
      指定者:
      invoke 在接口中 MethodInterceptor
      参数:
      invocation - the method invocation joinpoint
      返回:
      the result of the call to Joinpoint.proceed(), might be intercepted by the interceptor.
      抛出:
      Throwable - if the interceptors or the target-object throws an exception.
      另请参阅:
    • getLoggerForInvocation

      protected infra.logging.Logger getLoggerForInvocation(MethodInvocation invocation)
      Return the appropriate Logger instance to use for the given MethodInvocation. If the useDynamicLogger flag is set, the Logger instance will be for the target class of the MethodInvocation, otherwise the Logger will be the default static logger.
      参数:
      invocation - the MethodInvocation being traced
      返回:
      the Logger instance to use
      另请参阅:
    • getClassForLogging

      protected Class<?> getClassForLogging(Object target)
      Determine the class to use for logging purposes.
      参数:
      target - the target object to introspect
      返回:
      the target class for the given object
      另请参阅:
    • isInterceptorEnabled

      protected boolean isInterceptorEnabled(MethodInvocation invocation, infra.logging.Logger logger)
      Determine whether the interceptor should kick in, that is, whether the invokeUnderTrace method should be called.

      Default behavior is to check whether the given Logger instance is enabled. Subclasses can override this to apply the interceptor in other cases as well.

      参数:
      invocation - the MethodInvocation being traced
      logger - the Logger instance to check
      另请参阅:
    • isLogEnabled

      protected boolean isLogEnabled(infra.logging.Logger logger)
      Determine whether the given Logger instance is enabled.

      Default is true when the "trace" level is enabled. Subclasses can override this to change the level under which 'tracing' occurs.

      参数:
      logger - the Logger instance to check
    • writeToLog

      protected void writeToLog(infra.logging.Logger logger, String message)
      Write the supplied trace message to the supplied Logger instance.

      To be called by invokeUnderTrace(org.aopalliance.intercept.MethodInvocation, infra.logging.Logger) for enter/exit messages.

      Delegates to writeToLog(Logger, String, Throwable) as the ultimate delegate that controls the underlying logger invocation.

      另请参阅:
    • writeToLog

      protected void writeToLog(infra.logging.Logger logger, String message, Throwable ex)
      Write the supplied trace message and Throwable to the supplied Logger instance.

      To be called by invokeUnderTrace(org.aopalliance.intercept.MethodInvocation, infra.logging.Logger) for enter/exit outcomes, potentially including an exception. Note that an exception's stack trace won't get logged when setLogExceptionStackTrace(boolean) is "false".

      By default messages are written at TRACE level. Subclasses can override this method to control which level the message is written at, typically also overriding isLogEnabled(infra.logging.Logger) accordingly.

      另请参阅:
    • invokeUnderTrace

      protected abstract Object invokeUnderTrace(MethodInvocation invocation, infra.logging.Logger logger) throws Throwable
      Subclasses must override this method to perform any tracing around the supplied MethodInvocation. Subclasses are responsible for ensuring that the MethodInvocation actually executes by calling MethodInvocation.proceed().

      By default, the passed-in Logger instance will have log level "trace" enabled. Subclasses do not have to check for this again, unless they overwrite the isInterceptorEnabled method to modify the default behavior, and may delegate to writeToLog for actual messages to be written.

      参数:
      logger - the Logger to write trace messages to
      返回:
      the result of the call to MethodInvocation.proceed()
      抛出:
      Throwable - if the call to MethodInvocation.proceed() encountered any errors
      另请参阅: