From: Francois Fleuret Date: Fri, 16 Jun 2017 11:14:44 +0000 (+0200) Subject: Added elapsed time in logging. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=f829e951a7988cfc228af56fbcf17057cb61c06c;p=pysvrt.git Added elapsed time in logging. --- diff --git a/cnn-svrt.py b/cnn-svrt.py index 694f035..aa3690d 100755 --- a/cnn-svrt.py +++ b/cnn-svrt.py @@ -78,11 +78,20 @@ args = parser.parse_args() ###################################################################### log_file = open(args.log_file, 'w') +pred_log_t = None print(Fore.RED + 'Logging into ' + args.log_file + Style.RESET_ALL) def log_string(s): - s = Fore.GREEN + time.ctime() + Style.RESET_ALL + ' ' + s + global pred_log_t + t = time.time() + + if pred_log_t is None: + elapsed = 'start' + else: + elapsed = '+{:.02f}s'.format(t - pred_log_t) + pred_log_t = t + s = Fore.BLUE + time.ctime() + ' ' + Fore.GREEN + elapsed + Style.RESET_ALL + ' ' + s log_file.write(s + '\n') log_file.flush() print(s)