Skip to content

Commit fbba5ec

Browse files
committed
Directly configure no color output
1 parent 83686fd commit fbba5ec

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

colorlog/colorlog.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def __init__(
7878
secondary_log_colors: typing.Optional[SecondaryLogColors] = None,
7979
validate: bool = True,
8080
stream: typing.Optional[typing.IO] = None,
81+
no_color: bool = False,
8182
) -> None:
8283
"""
8384
Set the format and colors the ColoredFormatter will use.
@@ -122,6 +123,7 @@ def __init__(
122123
)
123124
self.reset = reset
124125
self.stream = stream
126+
self.no_color = no_color
125127

126128
def formatMessage(self, record: logging.LogRecord) -> str:
127129
"""Format a message from a record object."""
@@ -147,6 +149,9 @@ def _escape_code_map(self, item: str) -> EscapeCodes:
147149

148150
def _blank_escape_codes(self):
149151
"""Return True if we should be prevented from printing escape codes."""
152+
if self.no_color:
153+
return True
154+
150155
if "NO_COLOR" in os.environ:
151156
return True
152157

0 commit comments

Comments
 (0)