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?
I was facing similar issue, after changing the useDynamicLogger
to false the issue was fixed.
@Bean
public PerformanceMonitorInterceptor performanceMonitorInterceptor() {
return new PerformanceMonitorInterceptor(false);
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With