Skip to content

Commit 8400509

Browse files
committed
Logging: add exception information
Issue #162 Just cut and pasted from logging.py. Signed-off-by: Yves Bastide <yves@botify.com>
1 parent 37cd59d commit 8400509

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

simpleflow/settings/logging_formatter.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,27 @@ def format(self, record):
6060
record.isodate = date.isoformat()
6161
record.message = record.msg % record.args
6262
record.coloredlevel = colorize(record.levelname, record.levelname)
63-
return "%(isodate)s %(coloredlevel)s [process=%(processName)s, pid=%(process)s]: %(message)s" % record.__dict__
63+
s = "%(isodate)s %(coloredlevel)s [process=%(processName)s, pid=%(process)s]: %(message)s" % record.__dict__
64+
65+
# C&P from logging.Formatter#format
66+
if record.exc_info:
67+
# Cache the traceback text to avoid converting it multiple times
68+
# (it's constant anyway)
69+
if not record.exc_text:
70+
record.exc_text = self.formatException(record.exc_info)
71+
if record.exc_text:
72+
if s[-1:] != "\n":
73+
s = s + "\n"
74+
try:
75+
s = s + record.exc_text
76+
except UnicodeError:
77+
# Sometimes filenames have non-ASCII chars, which can lead
78+
# to errors when s is Unicode and record.exc_text is str
79+
# See issue 8924.
80+
# We also use replace for when there are multiple
81+
# encodings, e.g. UTF-8 for the filesystem and latin-1
82+
# for a script. See issue 13232.
83+
s = s + record.exc_text.decode(sys.getfilesystemencoding(),
84+
'replace')
85+
86+
return s

0 commit comments

Comments
 (0)