Skip to content

Commit 4fb09eb

Browse files
umu_log: do not use colors if stderr is not an interactive terminal
1 parent c2316d1 commit 4fb09eb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

umu/umu_log.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import sys
23
from logging import (
34
Formatter,
@@ -60,7 +61,8 @@ def format(self, record: LogRecord) -> str: # noqa: D102
6061
color = Color.WARNING
6162
case _:
6263
color = Color.BOLD
63-
record.levelname = f"{color}{Color.BOLD}{record.levelname}{Color.RESET}"
64+
if os.isatty(sys.stderr.fileno()):
65+
record.levelname = f"{color}{Color.BOLD}{record.levelname}{Color.RESET}"
6466
return super().format(record)
6567

6668

0 commit comments

Comments
 (0)