Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve handler filters if present (allows Filter(s) to work with coloredlogs) #89

Merged
merged 3 commits into from Dec 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions coloredlogs/__init__.py
Expand Up @@ -433,8 +433,13 @@ def install(level=None, **kw):
if use_colors or use_colors is None:
use_colors = terminal_supports_colors(stream)
# Create a stream handler.
# preserve any filters the current handler might have
preserved_filters = handler.filters if handler else None
handler = logging.StreamHandler(stream) if stream else StandardErrorHandler()
handler.setLevel(level)
# and add them back to the new handler
if preserved_filters:
handler.filters = preserved_filters
# Prepare the arguments to the formatter, allowing the caller to
# customize the values of `fmt', `datefmt' and `style' as desired.
formatter_options = dict(fmt=kw.get('fmt'), datefmt=kw.get('datefmt'))
Expand Down