]> granicus.if.org Git - python/commitdiff
logging: Formatter implementation tweak.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Mon, 25 Oct 2010 15:25:24 +0000 (15:25 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Mon, 25 Oct 2010 15:25:24 +0000 (15:25 +0000)
Lib/logging/__init__.py

index 0e29cf355c0f7f433a30158cb66a388fa9b1e56c..b6dd2339a04f8ca74a7268fd94a84f8b3f55c2ff 100644 (file)
@@ -482,6 +482,17 @@ class Formatter(object):
                      self._fmt.find("${asctime}") >= 0
         return result
 
+    def formatMessage(self, record):
+        style = self._style
+        if style == '%':
+            s = self._fmt % record.__dict__
+        elif style == '{':
+            s = self._fmt.format(**record.__dict__)
+        else:
+            from string import Template
+            s = Template(self._fmt).substitute(**record.__dict__)
+        return s
+
     def format(self, record):
         """
         Format the specified record as text.
@@ -498,14 +509,7 @@ class Formatter(object):
         record.message = record.getMessage()
         if self.usesTime():
             record.asctime = self.formatTime(record, self.datefmt)
-        style = self._style
-        if style == '%':
-            s = self._fmt % record.__dict__
-        elif style == '{':
-            s = self._fmt.format(**record.__dict__)
-        else:
-            from string import Template
-            s = Template(self._fmt).substitute(**record.__dict__)
+        s = self.formatMessage(record)
         if record.exc_info:
             # Cache the traceback text to avoid converting it multiple times
             # (it's constant anyway)