diff options
-rw-r--r-- | python/vyos/debug.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/python/vyos/debug.py b/python/vyos/debug.py index 91431a7bb..6ce42b173 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 _remove_invisible(string): for char in ('\0', '\a', '\b', '\f', '\v'): string = string.replace(char, '') |