Logging example does not output anything without a StreamHandler · Issue #2604 · googleapis/google-api-python-client · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Logging example does not output anything without a StreamHandler #2604

Open
@jnowakowski

Description

@jnowakowski

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p2Moderately-important priority. Fix may not be included in next release.type: processA process-related concern. May include testing, release, or the like.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      TMZ Celebrity News – Breaking Stories, Videos & Gossip

      Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

      Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

      🎥 Watch TMZ Live

      TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.