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

Importing google.cloud.logging.Client adds StreamHandler to root #6477

Closed
hnykda opened this issue Nov 12, 2018 · 3 comments
Closed

Importing google.cloud.logging.Client adds StreamHandler to root #6477

hnykda opened this issue Nov 12, 2018 · 3 comments
Assignees
Labels
api: logging Issues related to the Cloud Logging API. type: question Request for information or clarification. Not an issue.

Comments

@hnykda
Copy link

hnykda commented Nov 12, 2018

Importing a google cloud logging Client adds a handler to the root logger. That's IMO unexpected and may break users code. Imports must not have any side-effects.

A real-life example when it broke our code: our library has something like:

if logger.hasHandlers():
  initialize_logging()

but because we imported the Client somewhere on the beginning of the module, this didn't get executed.

Environment details

Python 3.7.0, docker image python:3.7-slim

Steps to reproduce

  1. docker run -ti python:3.7-slim bash
  2. pip install google-cloud-logging=1.8.0
  3. python:
root@45804a66c8d3:/# python
>>> import logging
>>> logging.root.handlers
[]
>>> from google.cloud.logging import Client
>>> logging.root.handlers
[<StreamHandler <stderr> (NOTSET)>]
@tseaver tseaver added type: question Request for information or clarification. Not an issue. api: logging Issues related to the Cloud Logging API. labels Nov 12, 2018
@tseaver
Copy link
Contributor

tseaver commented Nov 12, 2018

@hnykda The google-cloud-logging library does not itself add any handlers unless you call its setup_logging utility function. I believe that the issue is actually with the grpcio package, which has merged PRs to fix the issue:

I don't believe either of those fixes is available yet in a release.

@tseaver tseaver closed this as completed Nov 12, 2018
@tseaver
Copy link
Contributor

tseaver commented Nov 12, 2018

Looks like https://pypi.org/project/grpcio/1.16.1rc1/ contains the fix. You can upgrade to it via:

$ /path/to/venv/bin/pip install --upgrade grpcio==1.16.1rc1

@hnykda
Copy link
Author

hnykda commented Nov 12, 2018

Thanks for a quick resolution 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the Cloud Logging API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

2 participants