diff --git a/coloredlogs/__init__.py b/coloredlogs/__init__.py index 39d390a..5c072d2 100644 --- a/coloredlogs/__init__.py +++ b/coloredlogs/__init__.py @@ -434,11 +434,12 @@ def install(level=None, **kw): use_colors = terminal_supports_colors(stream) # Create a stream handler. # preserve any filters the current handler might have - preserved_filters = handler.filters + 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 - handler.filters = preserved_filters + 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'))