From c4010d51242df71926326a592620b82559bcd5f5 Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 29 Feb 2016 21:13:08 -0500 Subject: [PATCH 1/2] Fix KeyError exception when project has no logs --- cloud_logging/api/list_logs.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cloud_logging/api/list_logs.py b/cloud_logging/api/list_logs.py index c61daa894563..26a8eb6b3c64 100644 --- a/cloud_logging/api/list_logs.py +++ b/cloud_logging/api/list_logs.py @@ -25,6 +25,7 @@ # [START all] import argparse +import sys from googleapiclient import discovery from oauth2client.client import GoogleCredentials @@ -36,6 +37,9 @@ def list_logs(project_id, logging_service): while request: response = request.execute() + if len(response)==0: + print "No logs found in project {0}".format(project_id) + sys.exit(1) for log in response['logs']: print(log['name']) From bda970cbec3d77a3dded3fc7243d486aa95c12a3 Mon Sep 17 00:00:00 2001 From: danasmera Date: Tue, 1 Mar 2016 20:00:18 -0500 Subject: [PATCH 2/2] update fix for projects with no logs --- cloud_logging/api/list_logs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cloud_logging/api/list_logs.py b/cloud_logging/api/list_logs.py index 26a8eb6b3c64..83447a1c8d3a 100644 --- a/cloud_logging/api/list_logs.py +++ b/cloud_logging/api/list_logs.py @@ -37,9 +37,9 @@ def list_logs(project_id, logging_service): while request: response = request.execute() - if len(response)==0: - print "No logs found in project {0}".format(project_id) - sys.exit(1) + if not response: + print("No logs found in {0} project").format(project_id) + return False for log in response['logs']: print(log['name'])