force reading of django.settings (and thus logging)
Hi,
I have a small question:
I use settings.py:LOGGING in order to configure my logging
Now I'd like to add some log traces during the import phase
of a module using django
Example:
import logging
logger = logging.getLogger('mymodule')
logger.INFO('created logger')
import django.db
logger.INFO('another message')
What I see is following:
The message 'created logger' is not displayed
The message 'another message' is displayed
The reason is, that importing django.db was reading the setup file and
thus configuring the logging.
Now I wondered about the 'minimal' import required to convince django
reading its config.
I tried
from django.conf import settings
but this does not seem to read the settings as settings is a
<django.conf.LazySettings object>
Is there any 'standard' way of forcing the reading of the settings.
Accessing any member of django.conf.settings will force the reading and
enable logging, so what I can do is
from django.conf import settings
DEBUG = settings.DEBUG # force reading of django config
It just doesn't look really pythonic as this line makes only sense to a
user, who knows, that django.conf.settings is a lazy object.
Any suggestion for nicer code is welcome
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home