mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 13:31:32 +00:00
Print stack trace during an exception
This commit is contained in:
parent
3be018eb17
commit
882ab60490
@ -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):
|
||||||
|
Loading…
Reference in New Issue
Block a user