-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from FireTail-io/hotfix-handler-duplicates
Hotfix adding duplicating handlers registered to loggers
- Loading branch information
Showing
2 changed files
with
17 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
import logging | ||
import sys | ||
from threading import Lock | ||
|
||
|
||
def get_logger(debug): | ||
return __get_logger(debug, __name__) | ||
configured_loggers_lock = Lock() | ||
configured_loggers = set() | ||
|
||
|
||
def get_stdout_logger(debug): | ||
stdout_logger = __get_logger(debug, __name__ + "_stdout", logging.StreamHandler(sys.stdout)) | ||
stdout_logger.propagate = False | ||
return stdout_logger | ||
stdout_logger_name = __name__ + "_stdout" | ||
stdout_logger = logging.getLogger(stdout_logger_name) | ||
|
||
requires_config = False | ||
with configured_loggers_lock: | ||
if stdout_logger_name not in configured_loggers: | ||
configured_loggers.add(stdout_logger_name) | ||
requires_config = True | ||
|
||
def __get_logger(debug, name, handler=None): | ||
logger = logging.getLogger(name) | ||
logger.setLevel(logging.DEBUG if debug else logging.INFO) | ||
if handler: | ||
logger.addHandler(handler) | ||
return logger | ||
if requires_config: | ||
stdout_logger.propagate = False | ||
stdout_logger.setLevel(logging.DEBUG if debug else logging.INFO) | ||
stdout_logger.addHandler(logging.StreamHandler(sys.stdout)) | ||
|
||
return stdout_logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters