django-q
django-q copied to clipboard
Use logger.hasHandlers() to setup fallback logging
Instead of checking if the django-q logger has any handlers directly, use the hasHandlers 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
import logging
root_logger = logging.getLogger()
django_q_logger = logging.getLogger("django-q")
print("list of djando_q handlers", django_q_logger.handlers)
# []
print("does django_q have handlers?", django_q_logger.hasHandlers())
# False
root_logger.addHandler(logging.StreamHandler())
print("list of djando_q handlers", django_q_logger.handlers)
# []
print("does django_q have handlers?", django_q_logger.hasHandlers())
# True