10

I've got this simple bean for PerformanceMonitorInterceptor

@Configuration @EnableAspectJAutoProxy @Aspect public class PerfMetricsConfiguration { /** * Monitoring pointcut. */ @Pointcut("execution(* com.lapots.breed.judge.repository.*Repository.*(..))") public void monitor() { } /** * Creates instance of performance monitor interceptor. * @return performance monitor interceptor */ @Bean public PerformanceMonitorInterceptor performanceMonitorInterceptor() { return new PerformanceMonitorInterceptor(true); } /** * Creates instance of performance monitor advisor. * @return performance monitor advisor */ @Bean public Advisor performanceMonitorAdvisor() { AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); pointcut.setExpression("com.lapots.breed.judge.repository.PerfMetricsConfiguration.monitor()"); return new DefaultPointcutAdvisor(pointcut, performanceMonitorInterceptor()); } } 

It supposed to trace any method invocation in the interfaces that ends with Repository in name. I set logging level in application.properties

logging.level.org.springframework.aop.interceptor.PerformanceMonitorInterceptor=TRACE 

But during execution it doesn't write anything in the console. What's the problem?

9
  • Do you happen to be a colleague of the guy asking this question?. Never having seen any question of that kind ever before and now two within a few days is unlikely to be pure chance. Commented Mar 5, 2018 at 11:30
  • @kriegaex no I don't know him, but I recall asking similar question some time ago as aspects rarely works from the very beginning in my code lol Commented Mar 5, 2018 at 11:34
  • Your point cut will obviously not mach. setExpression takes an expression not a reference to a @Pointcut annotated method. Commented Mar 5, 2018 at 11:51
  • I took the code from here baeldung.com/spring-performance-logging Commented Mar 5, 2018 at 12:09
  • And did it ever work before you started changing the original? Commented Mar 6, 2018 at 13:22

4 Answers 4

15

I was facing similar issue, after changing the useDynamicLogger to false the issue was fixed.

@Bean public PerformanceMonitorInterceptor performanceMonitorInterceptor() { return new PerformanceMonitorInterceptor(false); } 
Sign up to request clarification or add additional context in comments.

Comments

6

Faced with the same issue. And as Manzoor suggested passing false to PerformanceMonitorInterceptor solves the problem.

Why? When you call new PerformanceMonitorInterceptor(true), the logger name used inside of PerformanceMonitorInterceptor will be: com.lapots.breed.judge.repository.SomeClass.

So in your particular case the following logging configuration is required: logging.level.com.lapots.breed.judge.repository=TRACE, otherwise you do not see any logs, the breakpoint on PerformanceMonitorInterceptor.invokeUnderTrace() will not work and you spend lot's of time thinking you have wrong AOP configuration (while actually it's fine), but you did not set up logging level for proper class/package.

Comments

4

I am using spring logging (SLF4J logging). Instead of putting PerformanceMonitorInterceptor logger to TRACE , I added com.lapots.breed.judge.repository logger to TRACE. This started printing logs for me.

I did this because the below method in AbstractTraceInterceptor is looking for TRACE enabled on the class(Repository) we executing but not on PerformanceMonitorInterceptor.

protected boolean isLogEnabled(Log logger) { return logger.isTraceEnabled(); } 

Comments

1

I just tried this, I simply added this to application.properties and it works:

logging.level.org.springframework.aop.interceptor.PerformanceMonitorInterceptor=trace

1 Comment

If this doesn't work, then probably you have some other logging config which is overriding this one.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.