Use logger.hasHandlers() to setup fallback logging (#13)

Instead of checking if the django-q logger has any handlers directly,
use the hasHandlers [1] method, which will check if any parent loggers
have handlers as well.

This fixes a bug where django-q configures it's own logging even though
the root logger has a handler set

 1. https://docs.python.org/3/library/logging.html#logging.Logger.hasHandlers

Co-authored-by: Wesley Ellis <wellis@benchsci.com>
This commit is contained in:
Stan Triepels
2022-10-15 17:39:51 +02:00
committed by GitHub
parent 9ace854290
commit 00fe611b86

View File

@@ -214,7 +214,7 @@ class Conf:
logger = logging.getLogger("django-q")
# Set up standard logging handler in case there is none
if not logger.handlers:
if not logger.hasHandlers():
logger.setLevel(level=getattr(logging, Conf.LOG_LEVEL))
logger.propagate = False
formatter = logging.Formatter(