Skip to content

Commit

Permalink
rewire root logger only if specified (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilija1 authored Sep 19, 2020
1 parent 34aafd4 commit c486b81
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions logtron/autodiscover.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def autodiscover(name=None, level=logging.INFO, **kwargs):
if not refresh and is_configured:
return logging.getLogger(name)

root_logger = logging.getLogger()
root_logger.setLevel(level)
existing_handlers = root_logger.handlers
[root_logger.removeHandler(i) for i in existing_handlers]
logger = logging.getLogger(name)
logger.setLevel(level)
while len(logger.handlers) > 0:
logger.removeHandler(logger.handlers[0])

discover_config = kwargs.get("discover_config", discover_config_base)
config = discover_config(kwargs.get("config"))
Expand All @@ -49,8 +49,8 @@ def autodiscover(name=None, level=logging.INFO, **kwargs):
)
handlers = __get_handlers(config, formatter)
for i in handlers:
root_logger.addHandler(i)
logger.addHandler(i)

is_configured = True

return logging.getLogger(name)
return logger
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "logtron"
version = "0.1.14"
version = "0.1.15"
description = "A simple logging library with JSON log formatting"
authors = ["Ilija Stevcev <ilija1@gmail.com>"]
license = "Apache-2.0"
Expand Down

0 comments on commit c486b81

Please sign in to comment.