From e04c22867cc8b339afb42613f2960ca5d37aa6b1 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 13 Jul 2015 12:45:08 +0300 Subject: [PATCH] Switch logs to use a single comprehension --- endpoints/api/superuser.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/endpoints/api/superuser.py b/endpoints/api/superuser.py index d5f664aab..d6266f2c4 100644 --- a/endpoints/api/superuser.py +++ b/endpoints/api/superuser.py @@ -46,15 +46,17 @@ class SuperUserGetLogsForService(ApiResource): if not service in get_services(): abort(404) + logs = [] try: with open(app.config['SYSTEM_LOGS_FILE'], 'r') as f: - logs = f.readlines() + logs = [line for line in f if line.find(service + '[') >= 0] + except Exception as ex: logger.exception('Cannot read logs') abort(400) return { - 'logs': '\n'.join([log for log in logs if log.find(service + '[') >= 0]) + 'logs': '\n'.join(logs) } abort(403)