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