Add logging parameter to retry decorator for automatic retry logging
Author: arnavsaxena62Created Jun 25, 2026Updated Jun 25, 2026
Currently, logging retry attempts with tenacity requires manually wiring before, after, and retry_error_callback hooks every time. This is verbose and repetitive for a common use case. Proposal: Add an optional logging parameter to the retry decorator that automatically sets sensible callbacks using stdlib logging:
python@retry(stop=stop_after_attempt(3), logging=True)
def my_function():
...This would log:
- Each retry attempt (attempt number, wait time)
- The final exception if all attempts fail
The existing before/after/retry_error_callback hooks remain unchanged, this is purely additive as a convenience wrapper over them.
Motivation: Similar to how requests integrates with logging automatically, this would make tenacity friendlier for production use without any breaking changes.
Source: jd/tenacity