diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2010-10-25 15:25:24 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2010-10-25 15:25:24 (GMT) |
commit | d0557bfe77eeedf9f59e6ba2954ab785095244dc (patch) | |
tree | 59d5f3a366ebea2f4a14399d5547f65330d0ac43 /Lib/logging | |
parent | a39c571061658967918276224a4992d1b421ae3f (diff) | |
download | cpython-d0557bfe77eeedf9f59e6ba2954ab785095244dc.zip cpython-d0557bfe77eeedf9f59e6ba2954ab785095244dc.tar.gz cpython-d0557bfe77eeedf9f59e6ba2954ab785095244dc.tar.bz2 |
logging: Formatter implementation tweak.
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/__init__.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 0e29cf3..b6dd233 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -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) |