Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Avoid mutating the root logger #119

Merged
merged 2 commits into from
May 2, 2018
Merged
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
11 changes: 9 additions & 2 deletions pydocumentdb/endpoint_discovery_retry_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@

import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
log_formatter = logging.Formatter('%(levelname)s:%(message)s')
log_handler = logging.StreamHandler()
log_handler.setFormatter(log_formatter)
logger.addHandler(log_handler)


class _EndpointDiscoveryRetryPolicy(object):
"""The endpoint discovery retry policy class used for geo-replicated database accounts
to handle the write forbidden exceptions due to writable/readable location changes
Expand All @@ -40,7 +48,6 @@ def __init__(self, global_endpoint_manager):
self._max_retry_attempt_count = _EndpointDiscoveryRetryPolicy.Max_retry_attempt_count
self.current_retry_attempt_count = 0
self.retry_after_in_milliseconds = _EndpointDiscoveryRetryPolicy.Retry_after_in_milliseconds
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also please retain the format of the logger.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't do that originally because it adds a little bit of boilerplate, but sure thing. Emulated the full basicConfig code path in bb74225, modeled on the Python 3.6.4 implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping @srinathnarayanan -- could you please take another look at the pull request?


def ShouldRetry(self, exception):
"""Returns true if should retry based on the passed-in exception.
Expand All @@ -53,7 +60,7 @@ def ShouldRetry(self, exception):
"""
if self.current_retry_attempt_count < self._max_retry_attempt_count and self.global_endpoint_manager.EnableEndpointDiscovery:
self.current_retry_attempt_count += 1
logging.info('Write location was changed, refreshing the locations list from database account and will retry the request.')
logger.info('Write location was changed, refreshing the locations list from database account and will retry the request.')

# Refresh the endpoint list to refresh the new writable and readable locations
self.global_endpoint_manager.RefreshEndpointList()
Expand Down