Opened 3 years ago

Closed 3 years ago

Last modified 3 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 3 years ago.
Here is a suggestion for the documentation.
ticket17680-second.diff (781 bytes) - added by vanessagomes 3 years ago.
Here is the patch with the suggestion.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 3 years ago by jezdez

  • Component changed from Uncategorized to Documentation
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 Changed 3 years ago by vanessagomes

  • Owner changed from nobody to vanessagomes

comment:3 Changed 3 years ago by Brian May <brian@…>

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.

Changed 3 years ago by vanessagomes

Here is a suggestion for the documentation.

comment:4 Changed 3 years ago by vanessagomes

  • Cc vanessagomes added
  • Has patch set

comment:5 Changed 3 years ago by claudep

  • 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 Changed 3 years ago by vanessagomes

claudep,

do you think that the note is unecessary?

comment:7 Changed 3 years ago by vanessagomes

I will adapt for your suggestion. It is cleaner.

Changed 3 years ago by vanessagomes

Here is the patch with the suggestion.

comment:8 Changed 3 years ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In [cb38fd9632f314bd78324083005dc8df55200390]:

Fixed #17680 - Clarified when logging is configured.

comment:9 Changed 3 years ago by Tim Graham <timograham@…>

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