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

Avoid mutating the root logger #119

Merged
merged 2 commits into from May 2, 2018

Conversation

Projects
None yet
2 participants
@c-w
Copy link
Contributor

commented Apr 24, 2018

Using logging.basicConfig(level=logging.INFO) mutates the root logger for the current Python interpreter. This means that any library which imports the pydocumentdb library will have its log level set to INFO which leads to unexpected behavior.

Some libraries even have tests to defend against this behavior, e.g. Celery: https://github.com/celery/celery/blob/120770929f/t/unit/conftest.py#L231-L244

To fix this unexpected behavior, this commit introduces a new logger that's specific to the endpoint discovery retry policy and only mutates the log level of that specific logger.

Avoid mutating the root logger
Using `logging.basicConfig(level=logging.INFO)` mutates the root logger
for the current Python interpreter. This means that any library which
imports the pydocumentdb library will have its log level set to INFO
which leads to unexpected behavior. Some libraries even have tests to
defend against this behavior, e.g. Celery:
https://github.com/celery/celery/blob/120770929f/t/unit/conftest.py#L231-L244

To fix this unexpected behavior, this commit introduces a new logger
that's specific to the endpoint discovery retry policy and only mutates
the log level of that specific logger.

@moderakh moderakh requested a review from srinathnarayanan Apr 25, 2018

@@ -40,7 +43,7 @@ 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)

This comment has been minimized.

Copy link
@srinathnarayanan

srinathnarayanan Apr 26, 2018

Contributor

Can you also please retain the format of the logger.

This comment has been minimized.

Copy link
@c-w

c-w Apr 26, 2018

Author Contributor

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.

This comment has been minimized.

Copy link
@c-w

c-w Apr 27, 2018

Author Contributor

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

@srinathnarayanan srinathnarayanan merged commit 6be607a into Azure:master May 2, 2018

1 check passed

license/cla All CLA requirements met.

@c-w c-w deleted the c-w:fix-root-logger-mutation branch May 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.