diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-05-07 06:23:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-07 06:23:05 +0200 |
commit | e3064f763f1976993a616e141dd9ce39165f6fe3 (patch) | |
tree | 593f93257a6b9d8dfc7ff852fc56dc819c8faf5b /python/vyos/debug.py | |
parent | 260ab097bda099665ec376fd49b9e8edc0ad52b9 (diff) | |
parent | 367094ff1764116089c9359e1e949db781a4a0da (diff) | |
download | vyos-1x-e3064f763f1976993a616e141dd9ce39165f6fe3.tar.gz vyos-1x-e3064f763f1976993a616e141dd9ce39165f6fe3.zip |
Merge pull request #391 from thomas-mangin/T1230
debug: T1230: add time information to saved debug logs
Diffstat (limited to 'python/vyos/debug.py')
-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, '') |