logging from command line
|Reported by:||Owned by:||vanessagomes|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
The documentation says "Logging is configured immediately after settings have been loaded. Since the loading of settings is one of the first things that Django does, you can be certain that loggers are always ready for use in your project code."
I assume this to be correct for web requests. It also seems to be correct for the "manage.py shell" interactive shell. It does not seem to work for command line applications however. For example, if I try to run the following code:
#!/usr/bin/env python from django.core.management import setup_environ from kgadmin.conf import settings setup_environ(settings) import logging logger = logging.getLogger(__name__) logger.debug(u"something weent debug") logger.info(u"something weent info") logger.error(u"something weent error")
then logging is not initialized and I get the following message:
No handlers could be found for logger "__main__"
To fix this, I have to insert code like the following to force the settings to become initialized:
import django.conf django.conf.settings.LOGGING
I would have hoped that setup_environ(...) would do all of this, but apparently not.
This is with python-django 1.3-2ubuntu1.1 running on Ubuntu 11.10
Change History (11)
comment:1 Changed 5 years ago by
|Component:||Uncategorized → Documentation|
|Triage Stage:||Unreviewed → Accepted|