From e9516e73796bbbda1be76e3f8b5d83cd84070830 Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Wed, 6 May 2020 17:03:05 +0100 Subject: debug: T1230: add time information to saved debug logs --- python/vyos/debug.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'python/vyos/debug.py') diff --git a/python/vyos/debug.py b/python/vyos/debug.py index 1a042cbb4..60e5291c1 100644 --- a/python/vyos/debug.py +++ b/python/vyos/debug.py @@ -15,7 +15,7 @@ import os import sys - +from datetime import datetime def message(message, flag='', destination=sys.stdout): """ @@ -46,7 +46,7 @@ def message(message, flag='', destination=sys.stdout): mask = os.umask(0o111) with open(logfile, 'a') as f: - f.write(_format('log', message)) + f.write(_timed(_format('log', message))) finally: os.umask(mask) @@ -81,6 +81,11 @@ def enabled(flag): return _fromenv(flag) or _fromfile(flag) +def _timed(message): + now = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + return f'{now} {message}' + + def _format(flag, message): """ format a log message -- cgit v1.2.3