[Python-checkins] r85836 - python/branches/py3k/Lib/logging/__init__.py

vinay.sajip python-checkins at python.org
Mon Oct 25 17:25:24 CEST 2010


Author: vinay.sajip
Date: Mon Oct 25 17:25:24 2010
New Revision: 85836

Log:
logging: Formatter implementation tweak.

Modified:
   python/branches/py3k/Lib/logging/__init__.py

Modified: python/branches/py3k/Lib/logging/__init__.py
==============================================================================
--- python/branches/py3k/Lib/logging/__init__.py	(original)
+++ python/branches/py3k/Lib/logging/__init__.py	Mon Oct 25 17:25:24 2010
@@ -482,6 +482,17 @@
                      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 @@
         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)


More information about the Python-checkins mailing list