Skip to content

Commit 10969b7

Browse files
committed
chore: improved error handling
1 parent a4f3fe7 commit 10969b7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

freqtrade/loggers/ft_rich_handler.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime
22
from logging import Handler
33

4+
from rich._null_file import NullFile
45
from rich.console import Console
56
from rich.text import Text
67
from rich.traceback import Traceback
@@ -27,6 +28,13 @@ def emit(self, record):
2728
log_level = Text(record.levelname, style=f"logging.level.{record.levelname.lower()}")
2829
gray_sep = Text(" - ", style="gray46")
2930

31+
if isinstance(self._console.file, NullFile):
32+
# Handles pythonw, where stdout/stderr are null, and we return NullFile
33+
# instance from Console.file. In this case, we still want to make a log record
34+
# even though we won't be writing anything to a file.
35+
self.handleError(record)
36+
return
37+
3038
self._console.print(
3139
Text() + log_time + gray_sep + name + gray_sep + log_level + gray_sep + msg
3240
)
@@ -36,7 +44,6 @@ def emit(self, record):
3644
tb = Traceback.from_exception(exc_type, exc_value, exc_traceback, extra_lines=1)
3745
self._console.print(tb)
3846

39-
self.flush()
4047
except RecursionError:
4148
raise
4249
except Exception:

0 commit comments

Comments
 (0)