tUse different timestamp for log messages - amprolla - devuan's apt repo merger HTML git clone git://parazyd.org/amprolla.git DIR Log DIR Files DIR Refs DIR README DIR LICENSE --- DIR commit e3fff494910cd263d90119ac1b73aef6d830446e DIR parent 76cbe816ad7cdfe728dcbea24029ecaedbc1287d HTML Author: parazyd <parazyd@dyne.org> Date: Sat, 9 Dec 2017 11:27:39 +0100 Use different timestamp for log messages Diffstat: M lib/log.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) --- DIR diff --git a/lib/log.py b/lib/log.py t@@ -4,7 +4,7 @@ Logging functions """ -from time import time +from time import strftime from os import makedirs from os.path import join import sys t@@ -12,11 +12,18 @@ import sys from lib.config import logdir +def timestamp(): + """ + Return current time in a certain format. + """ + return strftime("%Y/%m/%d %H:%M:%S") + + def die(msg, tofile=True): """ Log error and exit with exitcode 1 """ - msg = "%d [ERR] %s" % (int(time()), msg) + msg = "%s [ERR] %s" % (timestamp(), msg) print(msg) if tofile: logtofile('amprolla.txt', msg+'\n') t@@ -27,7 +34,7 @@ def warn(msg, tofile=True): """ Log warning and continue """ - msg = "%d [WARN] %s" % (int(time()), msg) + msg = "%s [WARN] %s" % (timestamp(), msg) print(msg) if tofile: logtofile('amprolla.txt', msg+'\n') t@@ -37,7 +44,7 @@ def info(msg, tofile=True): """ Log informational message and continue """ - msg = "%d [INFO] %s" % (int(time()), msg) + msg = "%s [INFO] %s" % (timestamp(), msg) print(msg) if tofile: logtofile('amprolla.txt', msg+'\n')