Skip to content

Logging Fixups #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cloud_logging/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Google Cloud Logging Samples
# Google Cloud Logging v1 Samples

**Note that these samples are for the v1 Samples, using the Google API Client.
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
Cloud client library.**

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

Expand Down
8 changes: 5 additions & 3 deletions logging/api/export_logs_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def list_sinks(client, args):

# [START list]
sinks = []
token = None
while True:
new_sinks, token = client.list_sinks()
new_sinks, token = client.list_sinks(page_token=token)
sinks += new_sinks
if token is None:
break
Expand All @@ -62,11 +63,12 @@ def update_sink(client, args):
will be exported to the destination.
"""
# Removes the robot in textPayload part of filter
# [START update]
sink = client.sink(
args.sink_name,
FILTER.format(args.project_id),
DESTINATION.format(args.destination_bucket))
# [START update]

sink.filter = ('logName="projects/{}/logs/syslog" '
'AND severity>= INFO'.format(sink.project))
print('Updated sink {}'.format(sink.name))
Expand All @@ -76,11 +78,11 @@ def update_sink(client, args):

def delete_sink(client, args):
"""Deletes a sink"""
# [START delete]
sink = client.sink(
args.sink_name,
FILTER.format(args.project_id),
DESTINATION.format(args.destination_bucket))
# [START delete]
sink.delete()
# [END delete]
print('Deleted sink {}'.format(sink.name))
Expand Down
12 changes: 7 additions & 5 deletions logging/api/logs_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,24 @@


def write_entry(client, args):
# [START write]
print('Writing log entry for logger '.format(args.logger_name))
mylogger = client.logger(args.logger_name)
# [START write]
mylogger.log_text(args.entry)
# [END write]


def list_entries(client, args):
"""Lists all entries for a logger"""
# [START list]
logger = client.logger(args.logger_name)
print('Listing all log entries for logger {}'.format(logger.name))
# [START list]
entries = []
token = None
while True:
new_entries, token = client.list_entries(filter_='logName="{}"'.format(
logger.full_name))
new_entries, token = client.list_entries(
filter_='logName="{}"'.format(logger.full_name),
page_token=token)
entries += new_entries
if token is None:
break
Expand All @@ -54,9 +56,9 @@ def delete_logger(client, args):

Note that a deletion can take several minutes to take effect.
"""
# [START delete]
logger = client.logger(args.logger_name)
print('Deleting all logging entries for {}'.format(logger.name))
# [START delete]
logger.delete()
# [END delete]

Expand Down