私はこの投稿に基づいてパフォーマンスログを実装しようとしています: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'? –