Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no logging for PerformanceMonitorInterceptor

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?

like image 367
lapots Avatar asked Mar 05 '18 09:03

lapots


2 Answers

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

@Bean
public PerformanceMonitorInterceptor performanceMonitorInterceptor() {
  return new PerformanceMonitorInterceptor(false);
}
like image 175
Manzoor Avatar answered Oct 22 '22 08:10

Manzoor


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.

like image 28
Kirill Avatar answered Oct 22 '22 09:10

Kirill