Open
Description
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
- Copy the logging example from https://googleapis.github.io/google-api-python-client/docs/logging.html
- Run the script in terminal or standard Python environment
- 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)