Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[run]
omit = rainbow_logging_handler/test/*
branch = True
parallel-mode = True
parallel = True


[report]
Expand Down
8 changes: 7 additions & 1 deletion rainbow_logging_handler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(
self, stream,

datefmt='%H:%M:%S',
ignore_tty_check=False,

color_name = ('white' , None, True),
color_levelno = ('white' , None, False),
Expand Down Expand Up @@ -92,6 +93,8 @@ def __init__(
:type color_*: str compatible to `time.strftime()` argument
:param datefmt: format of %(asctime)s, passed to `logging.Formatter.__init__()`.
If `None` is passed, `logging`'s default format of '%H:%M:%S,<milliseconds>' is used.
:param ignore_tty_check: don't check if the handler's stream is a terminal,
useful for compatibility with PyCharm
:type color_*: `(<symbolic name of foreground color>, <symbolic name of background color>, <brightness flag>)`
:param color_*: Each column's color. See `logging.Formatter` for supported column (`*`)
"""
Expand All @@ -100,6 +103,9 @@ def __init__(
# set timestamp format
self._datefmt = datefmt

# set if we should ignore stream's is_tty check
self._ignore_tty_check = ignore_tty_check

# set custom color
self._column_color['%(name)s'] = color_name
self._column_color['%(levelno)s'] = color_levelno
Expand Down Expand Up @@ -180,7 +186,7 @@ def format(self, record):

Takes a custom formatting path on a terminal.
"""
if self.is_tty:
if self._ignore_tty_check or self.is_tty:
message = self.colorize(record)
else:
message = logging.StreamHandler.format(self, record)
Expand Down