public @Bean CustomizableTraceInterceptor interceptor() { CustomizableTraceInterceptor interceptor = new CustomizableTraceInterceptor(); interceptor.setEnterMessage("Entering $[methodName]($[arguments])."); interceptor.setExitMessage("Leaving $[methodName](..) with return value $[returnValue], took $[invocationTime]ms."); return interceptor; }
@Test(expected = IllegalArgumentException.class) public void testSetEnterMessageWithInvocationTimePlaceholder() { // Must not be able to set enter message with invocation time placeholder new CustomizableTraceInterceptor().setEnterMessage(CustomizableTraceInterceptor.PLACEHOLDER_INVOCATION_TIME); }
@Test(expected = IllegalArgumentException.class) public void testSetEmptyExceptionMessage() { // Must not be able to set empty exception message new CustomizableTraceInterceptor().setExceptionMessage(""); }
@Test(expected = IllegalArgumentException.class) public void testSetEmptyEnterMessage() { // Must not be able to set empty enter message new CustomizableTraceInterceptor().setEnterMessage(""); }
@Test(expected = IllegalArgumentException.class) public void testSetExitMessageWithExceptionPlaceholder() { // Must not be able to set exit message with exception placeholder new CustomizableTraceInterceptor().setExitMessage(CustomizableTraceInterceptor.PLACEHOLDER_EXCEPTION); }
@Test(expected = IllegalArgumentException.class) public void testSetEnterMessageWithReturnValuePlaceholder() { // Must not be able to set enter message with return value placeholder new CustomizableTraceInterceptor().setEnterMessage(CustomizableTraceInterceptor.PLACEHOLDER_RETURN_VALUE); }
@Test(expected = IllegalArgumentException.class) public void testSetEnterMessageWithExceptionPlaceholder() { // Must not be able to set enter message with exception placeholder new CustomizableTraceInterceptor().setEnterMessage(CustomizableTraceInterceptor.PLACEHOLDER_EXCEPTION); }
@Test(expected = IllegalArgumentException.class) public void testSetEmptyExitMessage() { // Must not be able to set empty exit message new CustomizableTraceInterceptor().setExitMessage(""); }
@Test(expected = IllegalArgumentException.class) public void testSetExceptionMethodWithReturnValuePlaceholder() { // Must not be able to set exception message with return value placeholder new CustomizableTraceInterceptor().setExceptionMessage(CustomizableTraceInterceptor.PLACEHOLDER_RETURN_VALUE); }
@Bean public CustomizableTraceInterceptor interceptor() { CustomizableTraceInterceptor interceptor = new CustomizableTraceInterceptor(); interceptor.setEnterMessage("Entering $[methodName]($[arguments])."); interceptor.setExitMessage("Leaving $[methodName](..) with return value $[returnValue], took $[invocationTime]ms."); return interceptor; }
@Bean @Role(ROLE_INFRASTRUCTURE) public Advice traceInterceptor() { CustomizableTraceInterceptor traceInterceptor = new CustomizableTraceInterceptor(); traceInterceptor.setUseDynamicLogger(true); traceInterceptor.setEnterMessage("$[methodName]($[arguments])"); traceInterceptor.setExitMessage("~$[methodName]=$[returnValue] ($[invocationTime])"); traceInterceptor.setExceptionMessage("!$[methodName]"); return traceInterceptor; }
@Configuration @EnableAspectJAutoProxy public class SpringDataExecutionLoggingConfiguration { @Bean public CustomizableTraceInterceptor customizableTraceInterceptor() { CustomizableTraceInterceptor customizableTraceInterceptor = new CustomizableTraceInterceptor(); customizableTraceInterceptor.setUseDynamicLogger(true); customizableTraceInterceptor.setExitMessage("Executed $[methodName] in $[invocationTime]"); return customizableTraceInterceptor; } @Bean public Advisor advisor() { AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); pointcut.setExpression("execution(public * org.springframework.data.jpa.repository.CrudRepository+.*(..))"); return new DefaultPointcutAdvisor(pointcut, customizableTraceInterceptor()); } }