Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loggers duplication #203

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ dist/
poetry.lock
.vscode
.python-version
.idea
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [v2.2.2] - 2023-06-23

- Fix loggers duplication https://github.com/litl/backoff/issues/179

## [v2.2.1] - 2022-10-05

- Fix type hint for wait generators https://github.com/litl/backoff/issues/177
Expand Down
64 changes: 30 additions & 34 deletions backoff/_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,22 @@ def on_predicate(wait_gen: _WaitGenerator,
args will first be evaluated and their return values passed.
This is useful for runtime configuration.
"""
def decorate(target):
nonlocal logger, on_success, on_backoff, on_giveup

logger = _prepare_logger(logger)
on_success = _config_handlers(on_success)
on_backoff = _config_handlers(
on_backoff,
default_handler=_log_backoff,
logger=logger,
log_level=backoff_log_level
)
on_giveup = _config_handlers(
on_giveup,
default_handler=_log_giveup,
logger=logger,
log_level=giveup_log_level
)
logger = _prepare_logger(logger)
on_success = _config_handlers(on_success)
on_backoff = _config_handlers(
on_backoff,
default_handler=_log_backoff,
logger=logger,
log_level=backoff_log_level
)
on_giveup = _config_handlers(
on_giveup,
default_handler=_log_giveup,
logger=logger,
log_level=giveup_log_level
)

def decorate(target):
if asyncio.iscoroutinefunction(target):
retry = _async.retry_predicate
else:
Expand Down Expand Up @@ -180,24 +178,22 @@ def on_exception(wait_gen: _WaitGenerator,
args will first be evaluated and their return values passed.
This is useful for runtime configuration.
"""
def decorate(target):
nonlocal logger, on_success, on_backoff, on_giveup

logger = _prepare_logger(logger)
on_success = _config_handlers(on_success)
on_backoff = _config_handlers(
on_backoff,
default_handler=_log_backoff,
logger=logger,
log_level=backoff_log_level,
)
on_giveup = _config_handlers(
on_giveup,
default_handler=_log_giveup,
logger=logger,
log_level=giveup_log_level,
)
logger = _prepare_logger(logger)
on_success = _config_handlers(on_success)
on_backoff = _config_handlers(
on_backoff,
default_handler=_log_backoff,
logger=logger,
log_level=backoff_log_level,
)
on_giveup = _config_handlers(
on_giveup,
default_handler=_log_giveup,
logger=logger,
log_level=giveup_log_level,
)

def decorate(target):
if asyncio.iscoroutinefunction(target):
retry = _async.retry_exception
else:
Expand Down