瀏覽代碼

Real fix for #427

Ask Solem 12 年之前
父節點
當前提交
9e9674f44c
共有 1 個文件被更改,包括 10 次插入2 次删除
  1. 10 2
      celery/utils/log.py

+ 10 - 2
celery/utils/log.py

@@ -17,7 +17,7 @@ import traceback
 from billiard import current_process, util as mputil
 from kombu.log import get_logger as _get_logger, LOG_LEVELS
 
-from .encoding import safe_str
+from .encoding import safe_str, str_t
 from .term import colored
 
 _process_aware = False
@@ -87,7 +87,15 @@ class ColorFormatter(logging.Formatter):
 
         if self.use_color and color:
             try:
-                record.msg = safe_str(color(record.msg))
+                msg = record.msg
+                # safe_str will repr the color object
+                # and color will both on non-string objects
+                # so need to reorder calls based on type.
+                # Issue #427
+                if isinstance(msg, basestring):
+                    record.msg = str_t(color(safe_str(msg)))
+                else:
+                    record.msg = safe_str(color(msg))
             except Exception, exc:
                 record.msg = '<Unrepresentable %r: %r>' % (
                     type(record.msg), exc)