]> git-server-git.apps.pok.os.sepia.ceph.com Git - radosgw-agent.git/commitdiff
move the log module into util
authorAlfredo Deza <adeza@redhat.com>
Wed, 4 Mar 2015 15:49:02 +0000 (10:49 -0500)
committerAlfredo Deza <adeza@redhat.com>
Wed, 4 Mar 2015 15:49:02 +0000 (10:49 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
radosgw_agent/log.py [deleted file]
radosgw_agent/util/log.py [new file with mode: 0644]

diff --git a/radosgw_agent/log.py b/radosgw_agent/log.py
deleted file mode 100644 (file)
index f3ffeb3..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-import logging
-import sys
-
-BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
-
-COLORS = {
-    'WARNING': YELLOW,
-    'INFO': WHITE,
-    'DEBUG': BLUE,
-    'CRITICAL': RED,
-    'ERROR': RED,
-    'FATAL': RED,
-}
-
-RESET_SEQ = "\033[0m"
-COLOR_SEQ = "\033[1;%dm"
-BOLD_SEQ = "\033[1m"
-
-BASE_COLOR_FORMAT = "%(asctime)s %(process)d\
- [$BOLD%(name)s$RESET][%(color_levelname)-17s] %(message)s"
-
-BASE_FORMAT = "%(asctime)s %(process)d [%(name)s][%(levelname)-6s] %(message)s"
-
-
-def supports_color():
-    """
-    Returns True if the running system's terminal supports color, and False
-    otherwise.
-    """
-    unsupported_platform = (sys.platform in ('win32', 'Pocket PC'))
-    # isatty is not always implemented
-    is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
-    if unsupported_platform or not is_a_tty:
-        return False
-    return True
-
-
-def color_message(message):
-    message = message.replace("$RESET", RESET_SEQ).replace("$BOLD", BOLD_SEQ)
-    return message
-
-
-class ColoredFormatter(logging.Formatter):
-    """
-    A very basic logging formatter that not only applies color to the levels of
-    the ouput but will also truncate the level names so that they do not alter
-    the visuals of logging when presented on the terminal.
-    """
-
-    def __init__(self, msg):
-        logging.Formatter.__init__(self, msg)
-
-    def format(self, record):
-        levelname = record.levelname
-        truncated_level = record.levelname[:6]
-        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 and fall back to no colors if the system
-    does not support it
-    """
-    str_format = BASE_COLOR_FORMAT if supports_color() else BASE_FORMAT
-    color_format = color_message(str_format)
-    return ColoredFormatter(color_format)
diff --git a/radosgw_agent/util/log.py b/radosgw_agent/util/log.py
new file mode 100644 (file)
index 0000000..f3ffeb3
--- /dev/null
@@ -0,0 +1,69 @@
+import logging
+import sys
+
+BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
+
+COLORS = {
+    'WARNING': YELLOW,
+    'INFO': WHITE,
+    'DEBUG': BLUE,
+    'CRITICAL': RED,
+    'ERROR': RED,
+    'FATAL': RED,
+}
+
+RESET_SEQ = "\033[0m"
+COLOR_SEQ = "\033[1;%dm"
+BOLD_SEQ = "\033[1m"
+
+BASE_COLOR_FORMAT = "%(asctime)s %(process)d\
+ [$BOLD%(name)s$RESET][%(color_levelname)-17s] %(message)s"
+
+BASE_FORMAT = "%(asctime)s %(process)d [%(name)s][%(levelname)-6s] %(message)s"
+
+
+def supports_color():
+    """
+    Returns True if the running system's terminal supports color, and False
+    otherwise.
+    """
+    unsupported_platform = (sys.platform in ('win32', 'Pocket PC'))
+    # isatty is not always implemented
+    is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
+    if unsupported_platform or not is_a_tty:
+        return False
+    return True
+
+
+def color_message(message):
+    message = message.replace("$RESET", RESET_SEQ).replace("$BOLD", BOLD_SEQ)
+    return message
+
+
+class ColoredFormatter(logging.Formatter):
+    """
+    A very basic logging formatter that not only applies color to the levels of
+    the ouput but will also truncate the level names so that they do not alter
+    the visuals of logging when presented on the terminal.
+    """
+
+    def __init__(self, msg):
+        logging.Formatter.__init__(self, msg)
+
+    def format(self, record):
+        levelname = record.levelname
+        truncated_level = record.levelname[:6]
+        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 and fall back to no colors if the system
+    does not support it
+    """
+    str_format = BASE_COLOR_FORMAT if supports_color() else BASE_FORMAT
+    color_format = color_message(str_format)
+    return ColoredFormatter(color_format)