diff --git a/cloud_logging/README.md b/cloud_logging/README.md index 08da3270aaf..17661a39a6c 100644 --- a/cloud_logging/README.md +++ b/cloud_logging/README.md @@ -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). diff --git a/logging/api/export_logs_api.py b/logging/api/export_logs_api.py index f68efb991a9..3d87d40ed25 100644 --- a/logging/api/export_logs_api.py +++ b/logging/api/export_logs_api.py @@ -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 @@ -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)) @@ -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)) diff --git a/logging/api/logs_api.py b/logging/api/logs_api.py index 2ec6f6646b4..4fb8d028b21 100644 --- a/logging/api/logs_api.py +++ b/logging/api/logs_api.py @@ -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 @@ -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]