# HG changeset patch # User Matti Hamalainen # Date 1484642613 -7200 # Node ID 31e3100b5ed95c0182f2c958a24ced3ad98d2bd6 # Parent 80d566c1d061cfb846034aa25d3b046171e47616 Add timestamps to messages. diff -r 80d566c1d061 -r 31e3100b5ed9 multimerge.py --- a/multimerge.py Mon Nov 28 10:51:55 2016 +0200 +++ b/multimerge.py Tue Jan 17 10:43:33 2017 +0200 @@ -50,15 +50,23 @@ return gcm_log_levels.index(cfg.logging_level) +## Return a formatted timestamp string +def gcm_timestamp(stamp): + return time.strftime("%Y-%m-%d %H:%M:%S", stamp) + #.decode(locale.getlocale()[1]) + + ## Wrapper for print() that does not break when redirecting stdin/out ## because of piped output not having a defined encoding. We default ## to UTF-8 encoding in output here. def gcm_print(smsg): gcm_msgbuf.append(smsg) if sys.stdout.encoding != None: - print(smsg.encode(sys.stdout.encoding)) + rsmsg = smsg.encode(sys.stdout.encoding) else: - print(smsg.encode("UTF-8")) + rsmsg = smsg.encode("UTF-8") + + print("{0} | {1}".format(gcm_timestamp(time.localtime()), rsmsg)) ## Fatal error handler