Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aa9f265

Browse filesBrowse files
author
Bill Prin
committed
Logging Fixups
1) Bug fix, wasn’t passing in token to pagination 2) Rearrange region tags to include more 3) Have v1 samples recommend v2 samples
1 parent f574242 commit aa9f265
Copy full SHA for aa9f265

File tree

Expand file treeCollapse file tree

3 files changed

+17
-9
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+17
-9
lines changed

‎cloud_logging/README.md

Copy file name to clipboardExpand all lines: cloud_logging/README.md
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Google Cloud Logging Samples
1+
# Google Cloud Logging v1 Samples
2+
3+
**Note that these samples are for the v1 Samples, using the Google API Client.
4+
It's recommended you instead use the [Logging v2 samples](https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/logging/api), which use the Google
5+
Cloud client library.**
26

37
This section contains samples for [Google Cloud Logging](https://cloud.google.com/logging).
48

‎logging/api/export_logs_api.py

Copy file name to clipboardExpand all lines: logging/api/export_logs_api.py
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ def list_sinks(client, args):
4242

4343
# [START list]
4444
sinks = []
45+
token = None
4546
while True:
46-
new_sinks, token = client.list_sinks()
47+
new_sinks, token = client.list_sinks(page_token=token)
4748
sinks += new_sinks
4849
if token is None:
4950
break
@@ -62,11 +63,12 @@ def update_sink(client, args):
6263
will be exported to the destination.
6364
"""
6465
# Removes the robot in textPayload part of filter
66+
# [START update]
6567
sink = client.sink(
6668
args.sink_name,
6769
FILTER.format(args.project_id),
6870
DESTINATION.format(args.destination_bucket))
69-
# [START update]
71+
7072
sink.filter = ('logName="projects/{}/logs/syslog" '
7173
'AND severity>= INFO'.format(sink.project))
7274
print('Updated sink {}'.format(sink.name))
@@ -76,11 +78,11 @@ def update_sink(client, args):
7678

7779
def delete_sink(client, args):
7880
"""Deletes a sink"""
81+
# [START delete]
7982
sink = client.sink(
8083
args.sink_name,
8184
FILTER.format(args.project_id),
8285
DESTINATION.format(args.destination_bucket))
83-
# [START delete]
8486
sink.delete()
8587
# [END delete]
8688
print('Deleted sink {}'.format(sink.name))

‎logging/api/logs_api.py

Copy file name to clipboardExpand all lines: logging/api/logs_api.py
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,24 @@
2121

2222

2323
def write_entry(client, args):
24+
# [START write]
2425
print('Writing log entry for logger '.format(args.logger_name))
2526
mylogger = client.logger(args.logger_name)
26-
# [START write]
2727
mylogger.log_text(args.entry)
2828
# [END write]
2929

3030

3131
def list_entries(client, args):
3232
"""Lists all entries for a logger"""
33+
# [START list]
3334
logger = client.logger(args.logger_name)
3435
print('Listing all log entries for logger {}'.format(logger.name))
35-
# [START list]
3636
entries = []
37+
token = None
3738
while True:
38-
new_entries, token = client.list_entries(filter_='logName="{}"'.format(
39-
logger.full_name))
39+
new_entries, token = client.list_entries(
40+
filter_='logName="{}"'.format(logger.full_name),
41+
page_token=token)
4042
entries += new_entries
4143
if token is None:
4244
break
@@ -54,9 +56,9 @@ def delete_logger(client, args):
5456
5557
Note that a deletion can take several minutes to take effect.
5658
"""
59+
# [START delete]
5760
logger = client.logger(args.logger_name)
5861
print('Deleting all logging entries for {}'.format(logger.name))
59-
# [START delete]
6062
logger.delete()
6163
# [END delete]
6264

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.