我正在尝试基于此帖子实现性能日志记录:http://www.baeldung.com/spring-performance-logging。我想记录每个控制器端点和每个数据库请求。如果你想看到完整的项目,你可以找到它here。当我击中端点时,没有记录。在拦截器类中放置一个断点也不会停止。我已经将包的日志记录设置为跟踪级别。我错过了什么?我相信这是@PointCut
的东西,但看过文档后,我相信我是正确的。使用Spring Boot和AOP进行性能日志记录
拦截
public class PerformanceMonitorInterceptor extends AbstractMonitoringInterceptor
{
@Override
protected Object invokeUnderTrace(MethodInvocation methodInvocation, Log log) throws Throwable
{
String name = createInvocationTraceName(methodInvocation);
StopWatch stopWatch = new StopWatch();
stopWatch.start();
log.trace(String.format("Method %s execution start at %s", name, LocalDateTime.now()));
try
{
return methodInvocation.proceed();
}
finally
{
stopWatch.stop();
log.trace(String.format("Method %s execution took %dms (%s)", name,
stopWatch.getTotalTimeMillis(), DurationFormatUtils
.formatDurationWords(stopWatch.getTotalTimeMillis(), true, true)));
}
}
}
配置
@Configuration
@EnableAspectJAutoProxy
@Aspect
public class ContactControllerPerfLogConfig
{
@Bean
public PerformanceMonitorInterceptor performanceMonitorInterceptor()
{
return new PerformanceMonitorInterceptor();
}
// Any public method on the ContactController
@Pointcut("execution(public * org.example.phonebookexample.app.contact.ContactController.*(..))")
public void contactControllerMonitor()
{
}
@Bean
public Advisor contactControllerMonitorAdvisor(
PerformanceMonitorInterceptor performanceMonitorInterceptor)
{
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression("org.example.phonebookexample.app.contact.ContactControllerPerfLogConfig.contactControllerMonitor()");
return new DefaultPointcutAdvisor(pointcut, performanceMonitorInterceptor);
}
}
你有没有在'application.properties'中指定任何日志记录属性? –
是的,他们被设置在跟踪级别 – ndrone
你有没有试图改变它只:'logging.level = trace'? –