]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
[RM-13585] Add timestamp to console and log output
authorMartin Palma <martin@palma.bz>
Mon, 23 Nov 2015 15:32:15 +0000 (16:32 +0100)
committerMartin Palma <martin@palma.bz>
Mon, 23 Nov 2015 15:32:15 +0000 (16:32 +0100)
Signed-off-by: Martin Palma <martin@palma.bz>
ceph_deploy/util/log.py

index 6a298cf6d71b10ae0a36db77214254e7501dd965..6b687c04a99c5843662daf09ff4b5ca094f3b91a 100644 (file)
@@ -1,5 +1,6 @@
 import logging
 import sys
+import datetime
 
 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
 
@@ -16,8 +17,8 @@ RESET_SEQ = "\033[0m"
 COLOR_SEQ = "\033[1;%dm"
 BOLD_SEQ = "\033[1m"
 
-BASE_COLOR_FORMAT = "[$BOLD%(name)s$RESET][%(color_levelname)-17s] %(message)s"
-BASE_FORMAT = "[%(name)s][%(levelname)-6s] %(message)s"
+BASE_COLOR_FORMAT = "[%(timestamp)s][$BOLD%(name)s$RESET][%(color_levelname)-17s] %(message)s"
+BASE_FORMAT = "[%(timestamp)s][%(name)s][%(levelname)-6s] %(message)s"
 
 
 def supports_color():
@@ -53,6 +54,7 @@ class ColoredFormatter(logging.Formatter):
         truncated_level = record.levelname[:6]
         levelname_color = COLOR_SEQ % (30 + COLORS[levelname]) + truncated_level + RESET_SEQ
         record.color_levelname = levelname_color
+        record.timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
         return logging.Formatter.format(self, record)