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
Merged

Avoid mutating the root logger #119

merged 2 commits into from May 2, 2018

Conversation

@c-w
Copy link
Contributor

@c-w c-w 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.

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)
Copy link
Contributor

@srinathnarayanan srinathnarayanan Apr 26, 2018

Can you also please retain the format of the logger.

Copy link
Contributor Author

@c-w c-w Apr 26, 2018

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

@c-w c-w Apr 27, 2018

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
@c-w c-w deleted the 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
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants