Spring: Standard Logging aspect (interceptor)

aspectj, java, logging, spring

Solution

Yes there are!

<bean id="customizableTraceInterceptor" class="org.springframework.aop.interceptor.CustomizableTraceInterceptor">
    <property name="enterMessage" value="Entering $[methodName]($[arguments])"/>
    <property name="exitMessage" value="Leaving $[methodName](): $[returnValue]"/>
</bean>
<aop:config>
    <aop:advisor advice-ref="customizableTraceInterceptor" pointcut="execution(public * BankAccountServlet.*(..))"/>
</aop:config>

Check out the CustomizableTraceInterceptor API, you can define separate enter/exit/exception messages with several placeholders:

- `$[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

Problem

I've found a lot of examples on how to create a custom aspect for logging using the Spring framework like this or this but did not find standard/common Spring implementation for this situation and question. Are there any standard implementations of logging aspect from Spring or not?

Original source