summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Mangin <thomas.mangin@exa.net.uk>2020-05-06 17:03:05 +0100
committerThomas Mangin <thomas.mangin@exa.net.uk>2020-05-06 17:03:05 +0100
commite9516e73796bbbda1be76e3f8b5d83cd84070830 (patch)
tree48a4190e8a43eb687a3b6c444c53dcf55afef51d
parentf03dd18529b8c20c2183ab27e81a8d38699cf3f1 (diff)
downloadvyos-1x-e9516e73796bbbda1be76e3f8b5d83cd84070830.tar.gz
vyos-1x-e9516e73796bbbda1be76e3f8b5d83cd84070830.zip
debug: T1230: add time information to saved debug logs
-rw-r--r--python/vyos/debug.py9
1 files changed, 7 insertions, 2 deletions
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