mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 00:23:07 +00:00
feat: improve Rich traceback rendering
This commit is contained in:
@@ -7,6 +7,11 @@ from rich.traceback import Traceback
|
||||
|
||||
|
||||
class FtRichHandler(Handler):
|
||||
"""
|
||||
Basic colorized logging handler using Rich.
|
||||
Does not support all features of the standard logging handler, and uses a hard-coded log format
|
||||
"""
|
||||
|
||||
def __init__(self, console: Console, *args, **kwargs) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
self._console = console
|
||||
@@ -21,16 +26,15 @@ class FtRichHandler(Handler):
|
||||
name = Text(record.name, style="violet")
|
||||
log_level = Text(record.levelname, style=f"logging.level.{record.levelname.lower()}")
|
||||
gray_sep = Text(" - ", style="gray46")
|
||||
|
||||
self._console.print(
|
||||
Text() + log_time + gray_sep + name + gray_sep + log_level + gray_sep + msg
|
||||
)
|
||||
tb = None
|
||||
if record.exc_info:
|
||||
exc_type, exc_value, exc_traceback = record.exc_info
|
||||
tb = Traceback.from_exception(exc_type, exc_value, exc_traceback)
|
||||
self._console.print(Text() + log_time + gray_sep + name + gray_sep + log_level)
|
||||
self._console.print(tb)
|
||||
else:
|
||||
# pass
|
||||
self._console.print(
|
||||
Text() + log_time + gray_sep + name + gray_sep + log_level + gray_sep + msg
|
||||
)
|
||||
|
||||
self.flush()
|
||||
except RecursionError:
|
||||
|
||||
Reference in New Issue
Block a user