Fix ColoredFormatted: Colored record could affect other formatters.
authorRadek Brich <radek.brich@devl.cz>
Mon, 19 Aug 2013 16:32:33 +0200
changeset 10 51b7e98e1f41
parent 9 8d5a1affbb9d
child 11 d1f08fc9de31
Fix ColoredFormatted: Colored record could affect other formatters.
pycolib/coloredformatter.py
--- a/pycolib/coloredformatter.py	Mon Aug 19 14:18:26 2013 +0200
+++ b/pycolib/coloredformatter.py	Mon Aug 19 16:32:33 2013 +0200
@@ -35,7 +35,8 @@
 
     def format(self, record):
         """Override, add color as specified."""
-        original_record = copy(record)
+        # work on copy, do not alter original record, which is processed by other formatters too
+        record = copy(record)
 
         ### message color
         fg, bg = self.get_color('message', record)
@@ -47,10 +48,7 @@
         if fg or bg:
             record.levelname = highlight(1, fg, bg) + record.levelname + highlight(0)
 
-        res = logging.Formatter.format(self, record)
-
-        record = original_record
-        return res
+        return logging.Formatter.format(self, record)
 
 
     def set_color(self, fieldname, levelname, fg=None, bg=None):