jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/703500 )
Change subject: [IMPR] Cleanup _logging.Formatter ......................................................................
[IMPR] Cleanup _logging.Formatter
- move RotatingFileHandler.format method to the LoggingFormatter: each Handler may have its own Formatter. Handler.format calls the Formatter format: https://github.com/python/cpython/blob/3.9/Lib/logging/__init__.py - remove formatException because newline is already appended inside Formatter.format method it it is missing.
Bug: T286337 Change-Id: Ida4402af4424bc1075d3eda967a6d5d51f93cb85 --- M pywikibot/tools/_logging.py 1 file changed, 6 insertions(+), 15 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/tools/_logging.py b/pywikibot/tools/_logging.py index c6890aa..c3b79df 100644 --- a/pywikibot/tools/_logging.py +++ b/pywikibot/tools/_logging.py @@ -1,6 +1,6 @@ """Logging tools.""" # -# (C) Pywikibot team, 2009-2020 +# (C) Pywikibot team, 2009-2021 # # Distributed under the terms of the MIT license. # @@ -71,6 +71,11 @@ if not self.delay: self.stream = self._open()
+ +class LoggingFormatter(logging.Formatter): + + """Format LogRecords for output to file.""" + def format(self, record): """Strip trailing newlines before outputting text to file.""" # Warnings captured from the warnings system are not processed by @@ -88,17 +93,3 @@ record.args = (msg,)
return super().format(record).rstrip() - - -class LoggingFormatter(logging.Formatter): - - """Format LogRecords for output to file. - - This formatter *ignores* the 'newline' key of the LogRecord, because - every record written to a file must end with a newline, regardless of - whether the output to the user's console does. - """ - - def formatException(self, ei): - """Format and return the specified exception with newline.""" - return super().formatException(ei) + '\n'
pywikibot-commits@lists.wikimedia.org