Content-Length: 239713 | pFad | http://github.com/googleapis/google-api-python-client/issues/2604

E3 Logging example does not output anything without a StreamHandler · Issue #2604 · googleapis/google-api-python-client · GitHub
Skip to content

Logging example does not output anything without a StreamHandler #2604

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

Open
jnowakowski opened this issue May 19, 2025 · 1 comment · May be fixed by #2605
Open

Logging example does not output anything without a StreamHandler #2604

jnowakowski opened this issue May 19, 2025 · 1 comment · May be fixed by #2605
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: process A process-related concern. May include testing, release, or the like.

Comments

@jnowakowski
Copy link

Title

Logging example does not show output due to missing StreamHandler


Environment details

  • OS type and version: macOS 12.7
  • Python version: Python 3.10.13
  • pip version: pip 23.2.1
  • google-api-python-client version: 2.125.0

Steps to reproduce

  1. Copy the logging example from https://googleapis.github.io/google-api-python-client/docs/logging.html
  2. Run the script in terminal or standard Python environment
  3. No log output is shown, even though logging level is set to INFO

Code example

import logging
from googleapiclient.discovery import build

logger = logging.getLogger()
logger.setLevel(logging.INFO)

def main():
    service = build('translate', 'v2', developerKey='your_api_key')
    print(service.translations().list(
        source='en',
        target='fr',
        q=['flower', 'car']
    ).execute())

if __name__ == '__main__':
    main()

Stack trace

(no output shown unless developer adds a StreamHandler manually)

Description

The logging example in the documentation sets the logging level with logger.setLevel(logging.INFO) but does not include a StreamHandler.

As a result, no output appears in most environments (e.g. terminal, script execution), unless a handler is explicitly added to send logs to stdout.

This can confuse users trying to debug API usage.

Proposed fix:

Update the example to include:

import sys
handler = logging.StreamHandler(sys.stdout)
logger.addHandler(handler)
@ohmayr
Copy link
Contributor

ohmayr commented May 20, 2025

@jnowakowski Thanks for reporting this issue! I see that a handler isn't configured within the Python client and needs to be explicitly configured by the end user.

The following should do the trick:

logging.basicConfig(level=logging.INFO)

Alternatively, what you have looks good too! Thank you for submitting the PR. I'm triaging this issue to take a look at the PR.

@ohmayr ohmayr added type: process A process-related concern. May include testing, release, or the like. priority: p2 Moderately-important priority. Fix may not be included in next release. labels May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: process A process-related concern. May include testing, release, or the like.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/googleapis/google-api-python-client/issues/2604

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy