Spring @Retryable - how to log when it is invoked?

前端 未结 2 1149
粉色の甜心
粉色の甜心 2021-02-18 21:59

I use compile \'org.springframework.retry:spring-retry:1.2.2.RELEASE\'with Spring Boot 1.5.9.RELEASE.

Configured to retry my method and it work

2条回答
  •  故里飘歌
    2021-02-18 22:42

    Looking through the code the org.springframework.retry.support.RetryTemplate performs the retry logic for retrying the operations. This template only logs simple things like:

    o.s.retry.support.RetryTemplate          : Retry: count=0
    o.s.retry.support.RetryTemplate          : Checking for rethrow: count=1
    o.s.retry.support.RetryTemplate          : Retry: count=1
    o.s.retry.support.RetryTemplate          : Checking for rethrow: count=2
    o.s.retry.support.RetryTemplate          : Retry: count=2
    o.s.retry.support.RetryTemplate          : Checking for rethrow: count=3
    o.s.retry.support.RetryTemplate          : Retry failed last attempt: count=3
    

    If you want to log the specific exception you could catch the exception log it and rethrow. Unfortunately as far as i can see there is no way to log custom messages within the framework.

    Another method would be to shadow the actual interceptor responsible for the invocation of your method like RetryOperationsInterceptor, this is not advised however.

提交回复
热议问题