Mercurial > hg > gcmultimerge
changeset 129:31e3100b5ed9
Add timestamps to messages.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 17 Jan 2017 10:43:33 +0200 |
parents | 80d566c1d061 |
children | b33e3884182b |
files | multimerge.py |
diffstat | 1 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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