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 invocationThere are restrictions on which placeholders can be used in which messages: see the individual message properties for details on the valid placeholders.
setEnterMessage, setExitMessage, setExceptionMessage, SimpleTraceInterceptor
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final Set | ALLOWED_PLACEHOLDERS
The |
| private static final String | DEFAULT_ENTER_MESSAGE
The default message used for writing method entry messages. |
| private static final String | DEFAULT_EXCEPTION_MESSAGE
The default message used for writing exception messages. |
| private static final String | DEFAULT_EXIT_MESSAGE
The default message used for writing method exit messages. |
| private String | enterMessage
The message for method entry. |
| private String | exceptionMessage
The message for exceptions during method execution. |
| private String | exitMessage
The message for method exit. |
| private static final Pattern | PATTERN
The |
| public static final String | PLACEHOLDER_ARGUMENT_TYPES
The |
| public static final String | PLACEHOLDER_ARGUMENTS
The |
| public static final String | PLACEHOLDER_EXCEPTION
The |
| public static final String | PLACEHOLDER_INVOCATION_TIME
The |
| public static final String | PLACEHOLDER_METHOD_NAME
The |
| public static final String | PLACEHOLDER_RETURN_VALUE
The |
| public static final String | PLACEHOLDER_TARGET_CLASS_NAME
The |
| public static final String | PLACEHOLDER_TARGET_CLASS_SHORT_NAME
The |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private static void | appendArgumentTypes(MethodInvocation
the methodInvocation, Matcher MethodInvocation being logged.
Arguments will be retrieved from the corresponding Method.the matcher, StringBuilder Matcher containing the state of the outputthe output)StringBuilder containing the outputAdds a comma-separated list of the short |
| private static void | appendReturnValue(MethodInvocation
the methodInvocation, Matcher MethodInvocation that returned the valuethe matcher, StringBuilder Matcher containing the matched placeholderthe output, Object StringBuilder to write output tothe value returned by the method invocation. returnValue)Adds the |
| private static void | checkForInvalidPlaceholders(String message)
Checks to see if the supplied |
| protected Object | invokeUnderTrace(MethodInvocation invocation, Log
the logger)Log to write trace messages toImplements abstract org. Writes a log message before the invocation based on the value of |
| protected String | Returns: the formatted output to write to the logthe message template containing the placeholders to be replaced message, MethodInvocation the methodInvocation, Object MethodInvocation being logged.
Used to derive values for all placeholders except $[exception]
and $[returnValue].any value returned by the invocation.
Used to replace the returnValue, Throwable $[returnValue] placeholder. May be null.any throwable, long Throwable raised during the invocation.
The value of Throwable.toString() is replaced for the
$[exception] placeholder. May be null.the value to write in place of the
invocationTime)$[invocationTime] placeholderReplace the placeholders in the given message with the supplied values, or values derived from those supplied. |
| public void | |
| public void | setExceptionMessage(String exceptionMessage)
Set the template used for method exception log messages. |
| public void |
| ALLOWED_PLACEHOLDERS | back to summary |
|---|---|
| pack-priv static final Set<String> ALLOWED_PLACEHOLDERS The | |
| DEFAULT_ENTER_MESSAGE | back to summary |
|---|---|
| private static final String DEFAULT_ENTER_MESSAGE The default message used for writing method entry messages. | |
| DEFAULT_EXCEPTION_MESSAGE | back to summary |
|---|---|
| private static final String DEFAULT_EXCEPTION_MESSAGE The default message used for writing exception messages. | |
| DEFAULT_EXIT_MESSAGE | back to summary |
|---|---|
| private static final String DEFAULT_EXIT_MESSAGE The default message used for writing method exit messages. | |
| enterMessage | back to summary |
|---|---|
| private String enterMessage The message for method entry. | |
| exceptionMessage | back to summary |
|---|---|
| private String exceptionMessage The message for exceptions during method execution. | |
| exitMessage | back to summary |
|---|---|
| private String exitMessage The message for method exit. | |
| PATTERN | back to summary |
|---|---|
| private static final Pattern PATTERN The | |
| PLACEHOLDER_ARGUMENT_TYPES | back to summary |
|---|---|
| public static final String PLACEHOLDER_ARGUMENT_TYPES The | |
| PLACEHOLDER_ARGUMENTS | back to summary |
|---|---|
| public static final String PLACEHOLDER_ARGUMENTS The | |
| PLACEHOLDER_EXCEPTION | back to summary |
|---|---|
| public static final String PLACEHOLDER_EXCEPTION The | |
| PLACEHOLDER_INVOCATION_TIME | back to summary |
|---|---|
| public static final String PLACEHOLDER_INVOCATION_TIME The | |
| PLACEHOLDER_METHOD_NAME | back to summary |
|---|---|
| public static final String PLACEHOLDER_METHOD_NAME The | |
| PLACEHOLDER_RETURN_VALUE | back to summary |
|---|---|
| public static final String PLACEHOLDER_RETURN_VALUE The | |
| PLACEHOLDER_TARGET_CLASS_NAME | back to summary |
|---|---|
| public static final String PLACEHOLDER_TARGET_CLASS_NAME The | |
| PLACEHOLDER_TARGET_CLASS_SHORT_NAME | back to summary |
|---|---|
| public static final String PLACEHOLDER_TARGET_CLASS_SHORT_NAME The | |
| CustomizableTraceInterceptor | back to summary |
|---|---|
| public CustomizableTraceInterceptor() | |
| appendArgumentTypes | back to summary |
|---|---|
| private static void appendArgumentTypes(MethodInvocation methodInvocation, Matcher matcher, StringBuilder output) Adds a comma-separated list of the short
| |
| appendReturnValue | back to summary |
|---|---|
| private static void appendReturnValue(MethodInvocation methodInvocation, Matcher matcher, StringBuilder output, Object returnValue) Adds the
| |
| checkForInvalidPlaceholders | back to summary |
|---|---|
| private static void checkForInvalidPlaceholders(String message) throws IllegalArgumentException Checks to see if the supplied | |
| invokeUnderTrace | back to summary |
|---|---|
| protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable Implements abstract org. Writes a log message before the invocation based on the value of
| |
| replacePlaceholders | back to summary |
|---|---|
| protected String replacePlaceholders(String message, MethodInvocation methodInvocation, Object returnValue, Throwable throwable, long invocationTime) Replace the placeholders in the given message with the supplied values, or values derived from those supplied.
| |
| setEnterMessage | back to summary |
|---|---|
| public void setEnterMessage(String enterMessage) throws IllegalArgumentException Set the template used for method entry log messages. This template can contain any of the following placeholders:
| |
| setExceptionMessage | back to summary |
|---|---|
| public void setExceptionMessage(String exceptionMessage) Set the template used for method exception log messages. This template can contain any of the following placeholders:
| |
| setExitMessage | back to summary |
|---|---|
| public void setExitMessage(String exitMessage) Set the template used for method exit log messages. This template can contain any of the following placeholders:
| |