From 33b31a2451020127d71d5a1705764105aebf96ae Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 15 Jun 2015 20:55:23 -0400 Subject: [PATCH 1/2] Fix logs view in superuser panel This seems to have been broken ever since we moved to syslog --- config.py | 4 ++-- endpoints/api/superuser.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config.py b/config.py index 645a34462..a08e48a97 100644 --- a/config.py +++ b/config.py @@ -204,8 +204,8 @@ class DefaultConfig(object): # System logs. SYSTEM_LOGS_PATH = "/var/log/" - SYSTEM_SERVICE_LOGS_PATH = "/var/log/%s/current" - SYSTEM_SERVICES_PATH = "conf/init/" + SYSTEM_LOGS_FILE = "/var/log/syslog" + SYSTEM_SERVICES_PATH = "conf/init/service/" # Services that should not be shown in the logs view. SYSTEM_SERVICE_BLACKLIST = [] diff --git a/endpoints/api/superuser.py b/endpoints/api/superuser.py index 947b2a8db..d5f664aab 100644 --- a/endpoints/api/superuser.py +++ b/endpoints/api/superuser.py @@ -47,14 +47,14 @@ class SuperUserGetLogsForService(ApiResource): abort(404) try: - with open(app.config['SYSTEM_SERVICE_LOGS_PATH'] % service, 'r') as f: - logs = f.read() + with open(app.config['SYSTEM_LOGS_FILE'], 'r') as f: + logs = f.readlines() except Exception as ex: logger.exception('Cannot read logs') abort(400) return { - 'logs': logs + 'logs': '\n'.join([log for log in logs if log.find(service + '[') >= 0]) } abort(403) From e04c22867cc8b339afb42613f2960ca5d37aa6b1 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 13 Jul 2015 12:45:08 +0300 Subject: [PATCH 2/2] 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)