Skip to content

Commit

Permalink
Merge pull request #34 from FireTail-io/hotfix-handler-duplicates
Browse files Browse the repository at this point in the history
Hotfix adding duplicating handlers registered to loggers
  • Loading branch information
TheTeaCat authored Nov 20, 2023
2 parents 038a9dc + 756574c commit c697bb8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 16 additions & 12 deletions firetail/logger.py
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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ PyYAML==6.0.1
requests==2.31.0
starlette==0.27.0
werkzeug==2.2.3
swagger-ui-bundle==0.0.9
aiohttp_jinja2
aiohttp
aiohttp_remotes
pytest-aiohttp
starlette
a2wsgi
swagger-ui-bundle

0 comments on commit c697bb8

Please sign in to comment.