diff --git a/eth_retry/ENVIRONMENT_VARIABLES.py b/eth_retry/ENVIRONMENT_VARIABLES.py index a0fd7b5..4105fd2 100644 --- a/eth_retry/ENVIRONMENT_VARIABLES.py +++ b/eth_retry/ENVIRONMENT_VARIABLES.py @@ -3,6 +3,8 @@ ETH_RETRY_DISABLED = bool(os.environ.get("ETH_RETRY_DISABLED")) ETH_RETRY_DEBUG = bool(os.environ.get("ETH_RETRY_DEBUG")) -MIN_SLEEP_TIME = int(os.environ.get("MIN_SLEEP_TIME", 10)) -MAX_SLEEP_TIME = int(os.environ.get("MAX_SLEEP_TIME", 20)) +# NOTE: this will suppress logs up to `ETH_RETRY_SUPPRESS_LOGS` times, then they will log as usual +ETH_RETRY_SUPPRESS_LOGS = int(os.environ.get("ETH_RETRY_SUPPRESS_LOGS", -1)) +MIN_SLEEP_TIME = int(os.environ.get("MIN_SLEEP_TIME", 5)) +MAX_SLEEP_TIME = int(os.environ.get("MAX_SLEEP_TIME", 15)) MAX_RETRIES = int(os.environ.get("MAX_RETRIES", 10)) diff --git a/eth_retry/eth_retry.py b/eth_retry/eth_retry.py index ca2d45c..8fd15a5 100644 --- a/eth_retry/eth_retry.py +++ b/eth_retry/eth_retry.py @@ -64,7 +64,8 @@ def auto_retry_wrap(*args: P.args, **kwargs: P.kwargs) -> T: except Exception as e: if not should_retry(e, failures): raise - logger.warning(f'{str(e)} [{failures}]') + if failures > ENVS.ETH_RETRY_SUPPRESS_LOGS: + logger.warning(f'{str(e)} [{failures}]') if ENVS.ETH_RETRY_DEBUG: logger.exception(e) @@ -89,7 +90,8 @@ async def auto_retry_wrap_async(*args: P.args, **kwargs: P.kwargs) -> T: except Exception as e: if not should_retry(e, failures): raise - logger.warning(f'{str(e)} [{failures}]') + if failures > ENVS.ETH_RETRY_SUPPRESS_LOGS: + logger.warning(f'{str(e)} [{failures}]') if ENVS.ETH_RETRY_DEBUG: logger.exception(e)