]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Rename "normal" to "end_color" in log format strings.
authorBen Darnell <ben@bendarnell.com>
Tue, 7 Jan 2014 03:39:29 +0000 (22:39 -0500)
committerBen Darnell <ben@bendarnell.com>
Tue, 7 Jan 2014 03:42:43 +0000 (22:42 -0500)
When not colorizing, use empty strings instead of two copies of "normal".

Update docs.

docs/releases/next.rst
tornado/log.py

index 4e99ab18649d8aa6ad351a9b17408075c28b3669..3c96560d9f84ac9f0f37aeb12ed8c4f36da3ae37 100644 (file)
@@ -108,7 +108,7 @@ New modules
 
 * Fix an error from `tornado.log.enable_pretty_logging` when
   `sys.stderr` does not have an ``isatty`` method.
-* `tornado.log.LogFormatter` now accepts keyword arguments ``prefix_fmt``
+* `tornado.log.LogFormatter` now accepts keyword arguments ``fmt``
   and ``datefmt``.
 
 `tornado.netutil`
index 16b30f4804225044fec4e2852faf58c9bb1fc116..a4c7423482fe45e6df9471231657d91cf08ca395 100644 (file)
@@ -80,7 +80,7 @@ class LogFormatter(logging.Formatter):
     `tornado.options.parse_command_line` (unless ``--logging=none`` is
     used).
     """
-    DEFAULT_FORMAT = '%(color)s[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d]%(normal)s %(message)s'
+    DEFAULT_FORMAT = '%(color)s[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d]%(end_color)s %(message)s'
     DEFAULT_DATE_FORMAT = '%y%m%d %H:%M:%S'
     DEFAULT_COLORS = {
         logging.DEBUG:      4,  # Blue
@@ -95,7 +95,7 @@ class LogFormatter(logging.Formatter):
         :arg bool color: Enables color support.
         :arg string fmt: Log message format.
           It will be applied to the attributes dict of log records. The
-          text between ``%(color)s`` and ``%(normal)s`` will be colored
+          text between ``%(color)s`` and ``%(end_color)s`` will be colored
           depending on the level if color support is on.
         :arg dict colors: color mappings from logging level to terminal color
           code
@@ -104,7 +104,7 @@ class LogFormatter(logging.Formatter):
 
         .. versionchanged:: 3.2
 
-           Added ``prefix_fmt`` and ``datefmt`` arguments.
+           Added ``fmt`` and ``datefmt`` arguments.
         """
         logging.Formatter.__init__(self, datefmt=datefmt)
         self._fmt = fmt
@@ -155,8 +155,11 @@ class LogFormatter(logging.Formatter):
 
         record.asctime = self.formatTime(record, self.datefmt)
 
-        record.color = self._colors.get(record.levelno, self._normal)
-        record.normal = self._normal
+        if record.levelno in self._colors:
+            record.color = self._colors.get(record.levelno, '')
+            record.end_color = self._normal
+        else:
+            record.color = record.end_color = ''
 
         formatted = self._fmt % record.__dict__