Skip to content
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
9 changes: 8 additions & 1 deletion logging/cloud-client/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from google.cloud import logging


# [START logging_list_sinks]
def list_sinks():
"""Lists all sinks."""
logging_client = logging.Client()
Expand All @@ -30,8 +31,10 @@ def list_sinks():

for sink in sinks:
print('{}: {} -> {}'.format(sink.name, sink.filter_, sink.destination))
# [END logging_list_sinks]


# [START logging_create_sink]
def create_sink(sink_name, destination_bucket, filter_):
"""Creates a sink to export logs to the given Cloud Storage bucket.

Expand Down Expand Up @@ -61,8 +64,10 @@ def create_sink(sink_name, destination_bucket, filter_):

sink.create()
print('Created sink {}'.format(sink.name))
# [END logging_create_sink]


# [START logging_update_sink]
def update_sink(sink_name, filter_):
"""Changes a sink's filter.

Expand All @@ -80,9 +85,10 @@ def update_sink(sink_name, filter_):
sink.filter_ = filter_
print('Updated sink {}'.format(sink.name))
sink.update()
# [END update]
# [END logging_update_sink]


# [START logging_delete_sink]
def delete_sink(sink_name):
"""Deletes a sink."""
logging_client = logging.Client()
Expand All @@ -91,6 +97,7 @@ def delete_sink(sink_name):
sink.delete()

print('Deleted sink {}'.format(sink.name))
# [END logging_delete_sink]


if __name__ == '__main__':
Expand Down
6 changes: 6 additions & 0 deletions logging/cloud-client/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from google.cloud import logging


# [START logging_write_log_entry]
def write_entry(logger_name):
"""Writes log entries to the given logger."""
logging_client = logging.Client()
Expand All @@ -47,8 +48,10 @@ def write_entry(logger_name):
})

print('Wrote logs to {}.'.format(logger.name))
# [END logging_write_log_entry]


# [START logging_list_log_entries]
def list_entries(logger_name):
"""Lists the most recent entries for a given logger."""
logging_client = logging.Client()
Expand All @@ -60,8 +63,10 @@ def list_entries(logger_name):
timestamp = entry.timestamp.isoformat()
print('* {}: {}'.format
(timestamp, entry.payload))
# [END logging_list_log_entries]


# [START logging_delete_log]
def delete_logger(logger_name):
"""Deletes a logger and all its entries.

Expand All @@ -73,6 +78,7 @@ def delete_logger(logger_name):
logger.delete()

print('Deleted all logging entries for {}'.format(logger.name))
# [END logging_delete_log]


if __name__ == '__main__':
Expand Down