django-q icon indicating copy to clipboard operation
django-q copied to clipboard

Use logger.hasHandlers() to setup fallback logging

Open wesleyjellis opened this issue 2 years ago • 0 comments

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

wesleyjellis avatar Jun 13 '22 20:06 wesleyjellis