From 11a5a7b1727de7d60839e065cf0bcc1eab19294c Mon Sep 17 00:00:00 2001 From: Yoshi Yamaguchi <145104+ymotongpoo@users.noreply.github.com> Date: Mon, 29 Jun 2020 11:48:05 +0900 Subject: [PATCH 1/2] docs: add initialization of LogEntry instance in the v2 example --- README.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 220a6cf1..59065c15 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,7 @@ Python Client for Stackdriver Logging ===================================== -|pypi| |versions| +|pypi| |versions| `Stackdriver Logging API`_: Writes log entries and manages your Stackdriver Logging configuration. @@ -84,7 +84,9 @@ Using the API from google.cloud import logging_v2 client = logging_v2.LoggingServiceV2Client() - entries = [] + e = logging_v2.types.LogEntry( + text_payload="text") + entries = [e] response = client.write_log_entries(entries) .. code:: python From 0184dea68de63201faf5e24af65bdad82bbc8728 Mon Sep 17 00:00:00 2001 From: Yoshi Yamaguchi <145104+ymotongpoo@users.noreply.github.com> Date: Tue, 30 Jun 2020 08:48:55 +0900 Subject: [PATCH 2/2] docs: add more comments on log entry type and better log message --- README.rst | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 59065c15..fde18a47 100644 --- a/README.rst +++ b/README.rst @@ -82,10 +82,30 @@ Using the API .. code:: python from google.cloud import logging_v2 - client = logging_v2.LoggingServiceV2Client() + + resource = { + "type": "global", + "labels": { + "project_id": "[PROJECT_ID]" + } + } + + """ + Log entries can be either LogEntry or dict. + You can describe the same data in the following format: + + e = { + "log_name": "projects/[PROJECT_ID]/logs/test-logging", + "resource": resource, + "text_payload": "this is a log statement", + } + """ e = logging_v2.types.LogEntry( - text_payload="text") + log_name="projects/[PROJECT_ID]/logs/test-logging", # optional + resource=resource, # optional + text_payload="this is a log statement") + entries = [e] response = client.write_log_entries(entries)