mirror of
https://github.com/python/cpython.git
synced 2025-10-21 14:12:27 +00:00
logging: Formatter implementation tweak.
This commit is contained in:
parent
a39c571061
commit
d0557bfe77
1 changed files with 12 additions and 8 deletions
|
@ -482,6 +482,17 @@ class Formatter(object):
|
||||||
self._fmt.find("${asctime}") >= 0
|
self._fmt.find("${asctime}") >= 0
|
||||||
return result
|
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):
|
def format(self, record):
|
||||||
"""
|
"""
|
||||||
Format the specified record as text.
|
Format the specified record as text.
|
||||||
|
@ -498,14 +509,7 @@ class Formatter(object):
|
||||||
record.message = record.getMessage()
|
record.message = record.getMessage()
|
||||||
if self.usesTime():
|
if self.usesTime():
|
||||||
record.asctime = self.formatTime(record, self.datefmt)
|
record.asctime = self.formatTime(record, self.datefmt)
|
||||||
style = self._style
|
s = self.formatMessage(record)
|
||||||
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__)
|
|
||||||
if record.exc_info:
|
if record.exc_info:
|
||||||
# Cache the traceback text to avoid converting it multiple times
|
# Cache the traceback text to avoid converting it multiple times
|
||||||
# (it's constant anyway)
|
# (it's constant anyway)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue