Configuration of "level" in LOGGING

108 views
Skip to first unread message

Dan Swain

unread,
Apr 4, 2022, 9:26:02 PM4/4/22
to django-d...@googlegroups.com

The current Django LOGGING setup requires a string for the "level".  This is not intuitive since the Python logging module defines logging.DEBUG, logging.INFO, etc.  I think one should be able to configure the logging level using {  'level': logging.DEBUG  } rather than being required to use  {  'level': 'DEBUG'  }.

Jason Johns

unread,
Apr 4, 2022, 10:28:15 PM4/4/22
to Django developers (Contributions to Django itself)
How would this work with secret stores like hashicorp vault, aws secrets manager?  Or even via environment variables?  This approach would work if you define the logging level in your configuration, but not so friendly for other approaches.

Adam Johnson

unread,
Apr 5, 2022, 5:49:24 AM4/5/22
to Django developers (Contributions to Django itself)
Django doesn't require a string for log level. The contents of the LOGGING setting are passed directly to the callable in LOGGING_CONFIG, which defaults to logging.config.dictConfig, which takes numbers.

Demo:

In [1]: import logging

In [2]: from django.conf import settings

In [3]: import django

In [4]: settings.configure(LOGGING={"version": 1, "level": logging.CRITICAL})

In [5]: django.setup()

If there are some misleading docs, we could correct those, but I can't spot anything in the configuring logging page ( https://docs.djangoproject.com/en/4.0/topics/logging/#configuring-logging ) that says "level must be a string".

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/9e295cb2-e009-4a0a-b506-cb1ebec77761n%40googlegroups.com.

Kshitij Gavhane

unread,
Apr 5, 2022, 8:51:07 AM4/5/22
to django-d...@googlegroups.com
what if we just logg the key to python django level to retrieve logging info...?

On Tue, Apr 5, 2022 at 6:55 AM Dan Swain <d...@shenberger.org> wrote:

The current Django LOGGING setup requires a string for the "level".  This is not intuitive since the Python logging module defines logging.DEBUG, logging.INFO, etc.  I think one should be able to configure the logging level using {  'level': logging.DEBUG  } rather than being required to use  {  'level': 'DEBUG'  }.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.

Curtis Maloney

unread,
Apr 5, 2022, 8:51:07 AM4/5/22
to 'Mike Hansen' via Django developers (Contributions to Django itself)
On Tue, 5 Apr 2022, at 09:26, Dan Swain wrote:

The current Django LOGGING setup requires a string for the "level".  This is not intuitive since the Python logging module defines logging.DEBUG, logging.INFO, etc.  I think one should be able to configure the logging level using {  'level': logging.DEBUG  } rather than being required to use  {  'level': 'DEBUG'  }.


It's worth noting that Django, by default, uses python's own `logging.config.dictConfig` to process the LOGGING config object - https://docs.python.org/3/library/logging.config.html#logging.config.dictConfig

Since Python 3.2 `setLevel` has supported being passed a string of the name of the level: https://docs.python.org/3/library/logging.html#logging.Logger.setLevel

So the feature you're referring to is one from Python's stdlib.

Note: there is nothing to stop you from using `logging.DEBUG` if you prefer.

--
Curtis

Reply all
Reply to author
Forward
0 new messages