Switch logs to use a single comprehension

This commit is contained in:
Joseph Schorr 2015-07-13 12:45:08 +03:00
parent 33b31a2451
commit e04c22867c

View file

@ -46,15 +46,17 @@ class SuperUserGetLogsForService(ApiResource):
if not service in get_services(): if not service in get_services():
abort(404) abort(404)
logs = []
try: try:
with open(app.config['SYSTEM_LOGS_FILE'], 'r') as f: 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: except Exception as ex:
logger.exception('Cannot read logs') logger.exception('Cannot read logs')
abort(400) abort(400)
return { return {
'logs': '\n'.join([log for log in logs if log.find(service + '[') >= 0]) 'logs': '\n'.join(logs)
} }
abort(403) abort(403)