1
0
Fork 0
forked from github/pelican

Fix dictionary logging in formatter

Python special cases single Mapping arguments to logging. This
adjusts BaseFormatter to skip "fancy" formatting if argument
is of type Mapping. Also adds various formatted log outputs.
This commit is contained in:
Deniz Turgut 2020-05-09 19:39:54 +03:00
commit 50281c42e5
No known key found for this signature in database
GPG key ID: 87B7168D7AB3ED2F
3 changed files with 63 additions and 3 deletions

View file

@ -2,6 +2,7 @@ import logging
import os
import sys
from collections import defaultdict
from collections.abc import Mapping
__all__ = [
'init'
@ -18,9 +19,10 @@ class BaseFormatter(logging.Formatter):
record.__dict__['customlevelname'] = customlevel
# format multiline messages 'nicely' to make it clear they are together
record.msg = record.msg.replace('\n', '\n | ')
record.args = tuple(arg.replace('\n', '\n | ') if
isinstance(arg, str) else
arg for arg in record.args)
if not isinstance(record.args, Mapping):
record.args = tuple(arg.replace('\n', '\n | ') if
isinstance(arg, str) else
arg for arg in record.args)
return super().format(record)
def formatException(self, ei):