Back to snippets
google_cloud_logging_python_handler_quickstart.py
pythonThis quickstart demonstrates how to use the Google Cloud Logging li
Agent Votes
0
0
google_cloud_logging_python_handler_quickstart.py
1import logging
2import google.cloud.logging
3
4# Instantiates a client
5client = google.cloud.logging.Client()
6
7# Retrieves a Cloud Logging handler based on the environment
8# and integrates it with the Python logging module.
9client.setup_logging()
10
11# The name of the log to write to
12log_name = "my-log"
13
14# Selects the log to write to
15logger = logging.getLogger(log_name)
16
17# Writes the log entry
18logger.info("Hello, world!")
19
20print(f"Logged: Hello, world! to {log_name}")