I am trying to get Django logging to work on our dev server. I have read How do you log server errors on django sites which seems to be the definitive answer on the subject, and have copied the configuration from the answer https://stackoverflow.com/a/6395837/1094910 into my settings.py
(changing the output file for the WatchedFileHandler, of course; and adding my admin email address to settings.ADMINS
).
Neither the AdminEmailHandler nor the WatchedFileHandler are doing what they're supposed to do when I induce an error 500 on the site. I have set settings.DEBUG
to False
and have confirmed that Django can both send email and write to the file. I've also tried logging directly from the Django shell:
$ /usr/local/pythonenv/DJANGO/bin/python manage.py shell
...
>>> import logging
>>> l = logging.getLogger('django')
>>> l.handlers[0]
<logging.handlers.WatchedFileHandler instance at 0xcd3b48>
>>> l.error("This should write to a file")
>>> l = logging.getLogger('django.request')
>>> l.handlers[0]
<django.utils.log.AdminEmailHandler instance at 0xcd37e8>
>>> l.error("This should email the addresses in settings.ADMINS")
Neither logger emits a peep in the above case.
However, generic Python logging will work (for the file, at least), proving that it's not a file permission issue:
$ python # (or /usr/local/pythonenv/DJANGO/bin/python manage.py shell)
...
>>> import logging
>>> logging.basicConfig(filename='/path/to/same/file/as/above', level=logging.DEBUG)
>>> logging.error("This one shows up")
As noted above, Django can and happily will send emails throughout the rest of my project, just not in this case.
The WatchedFileHandler works on my local machine with the same configuration (except for file path of course); the AdminEmailHandler does not, but I suspect that is because I am using Gmail as an email server as described here. (Local machine is Windows 7; dev server on which the config doesn't work is Debian 6.0.3.)
I feel as though I'm missing something simple and obvious but have spent most of a day trying to figure out what it could be. Any suggestions as to what configurations I might have missed, or what other troubleshooting I should try, to figure out why Python's logging works but Django's doesn't?