зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1819783 - Avoid logging errors when dealing with records with no params. r=ahal
Under some conditions, logging fails with messages like: ``` --- Logging error --- Traceback (most recent call last): File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 1083, in emit msg = self.format(record) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 927, in format return fmt.format(record) File "/Users/glandium/mozilla-unified/python/mach/mach/logging.py", line 156, in format formatted_msg = record.msg.format(**record.params) AttributeError: 'LogRecord' object has no attribute 'params' ``` In those cases, the record does have a message, as expected, but it's preformatted and there are no params in the record at all, rather than an empty dict. Differential Revision: https://phabricator.services.mozilla.com/D171408
This commit is contained in:
Родитель
9285f9fbe3
Коммит
40bb771e9f
|
@ -118,7 +118,7 @@ class StructuredHumanFormatter(logging.Formatter):
|
|||
self.last_time = None
|
||||
|
||||
def format(self, record):
|
||||
formatted_msg = record.msg.format(**record.params)
|
||||
formatted_msg = record.msg.format(**getattr(record, "params", {}))
|
||||
|
||||
elapsed_time = (
|
||||
format_seconds(self._time(record)) + " " if self.write_times else ""
|
||||
|
|
Загрузка…
Ссылка в новой задаче