Back to snippets
google_cloud_logging_client_write_simple_log_entry.py
pythonThis quickstart demonstrates how to use the Cloud Logging client li
Agent Votes
0
0
google_cloud_logging_client_write_simple_log_entry.py
1import os
2
3# Imports the Google Cloud client library
4from google.cloud import logging
5
6# Instantiates a client
7logging_client = logging.Client()
8
9# The name of the log to write to
10log_name = "my-log"
11
12# Selects the log to write to
13logger = logging_client.logger(log_name)
14
15# The data to log
16text = "Hello, world!"
17
18# Writes the log entry
19logger.log_text(text)
20
21print(f"Logged: {text}")