Probably all your logging statements are executed right at file import
time before the logging is actually configured.
Just as a simple test, put such a logging statement inside one of your
view methods and hit it in your browser. Just to make sure your logging
setup as such works.
Reinout
--
Reinout van Rees http://reinout.vanrees.org/
rei...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"
So before your three lines:
> import logging
> logger = logging.getLogger('otherlogger')
> logger.warn('hello')
you had to be sure, that the django settings and thus the logging
configuration has really been completed.
You could for example add following two lines before:
> from django.conf import settings
> LOGGING = settings.LOGGING # force import
The second line is needed, as the first line is a 'lazy import' and will
only read the settings and configure logging when you access the first
time a element of settings.
I just used settings.LOGGING, as it should always exist, when you try to
log.
I am not sure whether there is a more elegant solution.
When I asked this question recently on this list, I didn't receive any
other suggestions.
> And that doesn't work either, unless I put it right in settings.py.. in
> which case it appears 4 times, because, from what I understand,
> settings.py gets loaded that many times. But then this doesn't work in
> the views.py/backend .. perhaps because the dictConfig gets loaded after
> settings.py is run? I don't know.
>
> I'm hoping for someone to give me a heads up about what I'm missing
> here. Django's been pretty easy to deal with until I started to look
> into logging.
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/JvmqgFNPMu4J.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
@Reinout: Thanks, but yeah, already tried logging from a view function..
didn't work...
@Bruno: Yeah, I am using the dev server. I have been using from django.conf
import settings within my app to access settings..although unless I do
something like what Gelondia suggested... with the LOGGING =
settings.LOGGING, I'm not sure how the logging normally "invokes" the
settings. The way I see it, django magically loads the settings at some
point in the background, then when you use the logging, it accesses those
settings, and there's a certain time when these settings become accessible
so this works. But it's not working like this, so perhaps I'm mistaken. So
you're saying to replace all instances of "from django.conf import settings"
with just "import settings"? Or the other way around? Not sure about what
importing only twice does, and how importing settings more or less affects
this.
Thanks all for answering.
--
View this message in context: http://old.nabble.com/Django-1.3-logging-not-working-as-I%27d-expect-tp32299898p32349226.html
Sent from the django-users mailing list archive at Nabble.com.
Gelonida N wrote:
>
> On 08/20/2011 06:51 AM, Scott Danzig wrote:
> You have to be sure, that logging is configured before actually logging
> anything.
>
> So before your three lines:
>> import logging
>> logger = logging.getLogger('otherlogger')
>> logger.warn('hello')
> you had to be sure, that the django settings and thus the logging
> configuration has really been completed.
>
> You could for example add following two lines before:
>> from django.conf import settings
>> LOGGING = settings.LOGGING # force import
>
> The second line is needed, as the first line is a 'lazy import' and will
> only read the settings and configure logging when you access the first
> time a element of settings.
> I just used settings.LOGGING, as it should always exist, when you try to
> log.
>
Thanks Gelonida.. tried your suggestion and added those two lines before my
import logging ... unfortunately no change. Perhaps it's not
straightforward. Sounds like it wasn't obvious to you either.
--
View this message in context: http://old.nabble.com/Django-1.3-logging-not-working-as-I%27d-expect-tp32299898p32349240.html
That's weird.
This works fine for me.
Just some more things to test:
Is ee, that you didn't add a root logger in your
log config.
you could add following two handlers.
'loggers': {
# root loggers
'': {
'handlers': ['console'],
'level': 'WARNING', # or 'DEBUG'
'propagate': True,
},
# not sure if this is really useful
'root': {
'handlers': ['console'],
'level': 'WARNING', # or 'DEBUG'
'propagate': True,
},
If this doesn't help you could add some print statements to be sure,
that your settings file is really read.
You could add a print statement after the assignment of
LOGGING in settings.py
LOGGING={ .. ..}
print "LOGGING VARIABLE IS SET NOW"
and in your file.
print "CHECKPOINT 1"
from django.conf import settings
print "CHECKPOINT 2"
LOGGING = settings.LOGGING # force import
print "CHECKPOINT 3"
import logging
logger = logging.getLogger('otherlogger')
print "CHECKPOINT 4"
logger.warn('hello')
print "CHECKPOINT 5"
What do you get as output?
Thanks all.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
--
View this message in context: http://old.nabble.com/Django-1.3-logging-not-working-as-I%27d-expect-tp32299898p32349771.html
Just for your info.
Forcing the import of 'settings.py' with the two lines, that I suggested
might be required in case, that your module might be
THE module using as very first module settings.py.
This is probaly NEVER the case when running in a 'normal' environment.
However for debugging I import some of my modules from a command line
script, which just sets
sys.path and
os.environ['DJANGO_SETTINGS_MODULE']
In this case you had to force the evaluation of settings.py before
creating a logger.
try executing
import logging
logger = logging.getLogger('testlogger')
logger.warn('hello')
logger.info('please appear')
in ./manage shell.
--
Alex