#17680 closed Bug (fixed)
logging from command line
Reported by: | Owned by: | vanessagomes | |
---|---|---|---|
Component: | Documentation | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | vanessagomes | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
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
Brian May
Attachments (2)
Change History (11)
comment:1 by , 13 years ago
Component: | Uncategorized → Documentation |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 12 years ago
Owner: | changed from | to
---|
comment:3 by , 12 years ago
In case it is not clear, should add that the import statement by itself was not sufficient. I had to access the settings in order to force them to load. As shown in my code example. Not sure if this is still the case now.
by , 12 years ago
Attachment: | ticket17680-patch.diff added |
---|
Here is a suggestion for the documentation.
comment:4 by , 12 years ago
Cc: | added |
---|---|
Has patch: | set |
comment:5 by , 12 years ago
Patch needs improvement: | set |
---|
I would have simply replaced the sentence:
Logging is configured immediately after settings have been loaded.
By:
Logging is configured as soon as settings have been loaded (either manually or when at least one setting is accessed).
With a link to https://docs.djangoproject.com/en/dev/topics/settings/#django.conf.settings.configure on the word "manually".
comment:8 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I believe the docs try to say "Logging is configured immediately after settings have been loaded *by importing them*.." or something like that. In other words, this seems like a documentation issue.