Skip to content

Commit ce40c51

Browse files
committed
Catch exception in non-console context rather than detecting pytest
Exception was also occuring in other non-console contexts, e.g. sphinx
1 parent 9ddca41 commit ce40c51

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/fastcs/logging/_logging.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ def _configure_logger(
3131
graylog_env_fields: GraylogEnvFields | None = None,
3232
):
3333
logger.remove()
34-
is_pytest_on_windows = "PYTEST_VERSION" in os.environ and os.name == "nt"
34+
35+
try:
36+
out = StdoutProxy(raw=True)
37+
except Exception:
38+
# e.g. prompt_toolkit.output.win32.NoConsoleScreenBufferError on windows
39+
# But it isn't exported from prompt_toolkit in a cross-platform way.
40+
out = sys.stdout
41+
3542
logger.add(
36-
sink=sys.stdout if is_pytest_on_windows else StdoutProxy(raw=True), # type: ignore
43+
sink=out, # type: ignore
3744
colorize=True,
3845
format=format_record,
3946
level=level or "INFO",

0 commit comments

Comments
 (0)