Print stack trace during an exception

This commit is contained in:
R. Richard 2019-07-02 15:39:46 +02:00
parent 3be018eb17
commit 882ab60490

View File

@ -2,6 +2,7 @@
from datetime import datetime from datetime import datetime
from typing import TextIO, Union from typing import TextIO, Union
from dataclasses import dataclass from dataclasses import dataclass
from traceback import format_exception
from logging import DEBUG, getLogger, Handler, Formatter, Filter from logging import DEBUG, getLogger, Handler, Formatter, Filter
@ -86,10 +87,11 @@ class LogFormatter(Formatter):
message = record.msg % clean_args message = record.msg % clean_args
else: else:
message = record.msg message = record.msg
trace = '\n'+''.join(format_exception(*record.exc_info)) if record.exc_info else ''
return (f'[{Color.GREY}{date}{Color.RESET}|>' return (f'[{Color.GREY}{date}{Color.RESET}|>'
f'{self.severity_to_color[record.levelname]}{record.module}:' f'{self.severity_to_color[record.levelname]}{record.module}:'
f'{record.levelname.lower()}{Color.RESET}] {message}') f'{record.levelname.lower()}{Color.RESET}] {message}{trace}')
def trim(self, value): def trim(self, value):
if isinstance(value, dict): if isinstance(value, dict):
@ -107,9 +109,10 @@ class VerboseLogFormatter(Formatter):
message = record.msg % record.args message = record.msg % record.args
else: else:
message = record.msg message = record.msg
trace = '\n'+''.join(format_exception(*record.exc_info)) if record.exc_info else ''
return (f'[{date}|>{record.module}:{record.levelname.lower()}] ' return (f'[{date}|>{record.module}:{record.levelname.lower()}] '
f'{message}') f'{message}{trace}')
class WhitelistFilter(Filter): class WhitelistFilter(Filter):