Skip to content

Commit

Permalink
ApiClient: Enable logging of Tenacity retry attempts at INFO level
Browse files Browse the repository at this point in the history
* Also fix Configuration.debug() to enable these messages to propagate by default
  (The default log level is not WARNING, it's NOTSET, meaning inherit from parent)
  • Loading branch information
asqui committed Apr 24, 2020
1 parent 5fceef1 commit 13a731c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 4 additions & 1 deletion opsgenie_sdk/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import copy
import datetime
import json
import logging
import mimetypes
from multiprocessing.pool import ThreadPool
import os
Expand All @@ -33,6 +34,7 @@
from opsgenie_sdk import rest
from opsgenie_sdk.configuration import Configuration
from opsgenie_sdk.exceptions import ApiValueError, RetryableException
from tenacity import before_sleep_log


class ApiClient(object):
Expand Down Expand Up @@ -81,7 +83,8 @@ def __init__(self, configuration=None, header_name=None, header_value=None,
wait=tenacity.wait_random_exponential(multiplier=configuration.back_off,
max=configuration.retry_delay),
retry=(tenacity.retry_if_exception_type(RetryableException) |
(tenacity.retry_if_exception_type(HTTPError))))
(tenacity.retry_if_exception_type(HTTPError))),
before_sleep=before_sleep_log(logging.getLogger("opsgenie_sdk"), logging.INFO, exc_info=True))

self.rest_client = rest.RESTClientObject(configuration, retrying=self.retrying)
self.default_headers = {}
Expand Down
5 changes: 2 additions & 3 deletions opsgenie_sdk/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,9 @@ def debug(self, value):
# turn on httplib debug
httplib.HTTPConnection.debuglevel = 1
else:
# if debug status is False, turn off debug logging,
# setting log level to default `logging.WARNING`
# if debug status is False, turn off debug logging
for _, logger in six.iteritems(self.logger):
logger.setLevel(logging.WARNING)
logger.setLevel(logging.NOTSET)
# turn off httplib debug
httplib.HTTPConnection.debuglevel = 0

Expand Down

0 comments on commit 13a731c

Please sign in to comment.