comparison multimerge.py @ 129:31e3100b5ed9

Add timestamps to messages.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 17 Jan 2017 10:43:33 +0200
parents bb8b455218ec
children b33e3884182b
comparison
equal deleted inserted replaced
128:80d566c1d061 129:31e3100b5ed9
48 48
49 def gcm_get_log_level(): 49 def gcm_get_log_level():
50 return gcm_log_levels.index(cfg.logging_level) 50 return gcm_log_levels.index(cfg.logging_level)
51 51
52 52
53 ## Return a formatted timestamp string
54 def gcm_timestamp(stamp):
55 return time.strftime("%Y-%m-%d %H:%M:%S", stamp)
56 #.decode(locale.getlocale()[1])
57
58
53 ## Wrapper for print() that does not break when redirecting stdin/out 59 ## Wrapper for print() that does not break when redirecting stdin/out
54 ## because of piped output not having a defined encoding. We default 60 ## because of piped output not having a defined encoding. We default
55 ## to UTF-8 encoding in output here. 61 ## to UTF-8 encoding in output here.
56 def gcm_print(smsg): 62 def gcm_print(smsg):
57 gcm_msgbuf.append(smsg) 63 gcm_msgbuf.append(smsg)
58 if sys.stdout.encoding != None: 64 if sys.stdout.encoding != None:
59 print(smsg.encode(sys.stdout.encoding)) 65 rsmsg = smsg.encode(sys.stdout.encoding)
60 else: 66 else:
61 print(smsg.encode("UTF-8")) 67 rsmsg = smsg.encode("UTF-8")
68
69 print("{0} | {1}".format(gcm_timestamp(time.localtime()), rsmsg))
62 70
63 71
64 ## Fatal error handler 72 ## Fatal error handler
65 def gcm_fatal(smsg): 73 def gcm_fatal(smsg):
66 gcm_print(u"ERROR: "+ smsg) 74 gcm_print(u"ERROR: "+ smsg)