Skip to content

Add logging parameter to retry decorator for automatic retry logging #644

Description

@arnavsaxena62

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions