Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#17680 closed Bug (fixed)

logging from command line

Reported by: Brian May <brian@…> 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)

ticket17680-patch.diff (832 bytes ) - added by vanessagomes 12 years ago.
Here is a suggestion for the documentation.
ticket17680-second.diff (781 bytes ) - added by vanessagomes 12 years ago.
Here is the patch with the suggestion.

Download all attachments as: .zip

Change History (11)

comment:1 by Jannis Leidel, 13 years ago

Component: UncategorizedDocumentation
Triage Stage: UnreviewedAccepted

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.

comment:2 by vanessagomes, 12 years ago

Owner: changed from nobody to vanessagomes

comment:3 by Brian May <brian@…>, 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 vanessagomes, 12 years ago

Attachment: ticket17680-patch.diff added

Here is a suggestion for the documentation.

comment:4 by vanessagomes, 12 years ago

Cc: vanessagomes added
Has patch: set

comment:5 by Claude Paroz, 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:6 by vanessagomes, 12 years ago

claudep,

do you think that the note is unecessary?

comment:7 by vanessagomes, 12 years ago

I will adapt for your suggestion. It is cleaner.

by vanessagomes, 12 years ago

Attachment: ticket17680-second.diff added

Here is the patch with the suggestion.

comment:8 by Tim Graham <timograham@…>, 12 years ago

Resolution: fixed
Status: newclosed

In [cb38fd9632f314bd78324083005dc8df55200390]:

Fixed #17680 - Clarified when logging is configured.

comment:9 by Tim Graham <timograham@…>, 12 years ago

In [3264894ee02f7099272619fa4f6072d4d2e95eb6]:

[1.4.X] Fixed #17680 - Clarified when logging is configured.

Backport of cb38fd9632 from master

Note: See TracTickets for help on using tickets.
Back to Top