]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
fall back without padding if no colors 159/head
authorAlfredo Deza <alfredo.deza@inktank.com>
Fri, 31 Jan 2014 17:34:01 +0000 (12:34 -0500)
committerAlfredo Deza <alfredo.deza@inktank.com>
Fri, 31 Jan 2014 17:37:38 +0000 (12:37 -0500)
Signed-off-by: Alfredo Deza <alfredo.deza@inktank.com>
ceph_deploy/util/log.py

index 2a236befdf85dbc99a4455d3110e144edeee4bc8..6a298cf6d71b10ae0a36db77214254e7501dd965 100644 (file)
@@ -8,7 +8,8 @@ COLORS = {
     'INFO': WHITE,
     'DEBUG': BLUE,
     'CRITICAL': RED,
-    'ERROR': RED
+    'ERROR': RED,
+    'FATAL': RED,
 }
 
 RESET_SEQ = "\033[0m"
@@ -16,7 +17,7 @@ COLOR_SEQ = "\033[1;%dm"
 BOLD_SEQ = "\033[1m"
 
 BASE_COLOR_FORMAT = "[$BOLD%(name)s$RESET][%(color_levelname)-17s] %(message)s"
-BASE_FORMAT = "%(asctime)s [%(name)s][%(levelname)-6s] %(message)s"
+BASE_FORMAT = "[%(name)s][%(levelname)-6s] %(message)s"
 
 
 def supports_color():
@@ -50,18 +51,17 @@ class ColoredFormatter(logging.Formatter):
     def format(self, record):
         levelname = record.levelname
         truncated_level = record.levelname[:6]
-        if levelname in COLORS and supports_color():
-            levelname_color = COLOR_SEQ % (30 + COLORS[levelname]) + truncated_level + RESET_SEQ
-            record.color_levelname = levelname_color
-        else:
-            record.color_levelname = levelname
+        levelname_color = COLOR_SEQ % (30 + COLORS[levelname]) + truncated_level + RESET_SEQ
+        record.color_levelname = levelname_color
         return logging.Formatter.format(self, record)
 
 
 def color_format():
     """
     Main entry point to get a colored formatter, it will use the
-    BASE_FORMAT by default.
+    BASE_FORMAT by default and fall back to no colors if the system
+    does not support it
     """
-    color_format = color_message(BASE_COLOR_FORMAT)
+    str_format = BASE_COLOR_FORMAT if supports_color() else BASE_FORMAT
+    color_format = color_message(str_format)
     return ColoredFormatter(color_format)