I've got error emails setup via Django's logging mechanism in 1.3. It sends me a nice email when an error happens. However, when I log a simple error message it's being formatted oddly and I'm not sure why.
For example, there's a condition in my app where if something doesn't exist in the DB I want to know about, but I have a suitable default value that will work fine. Thus, I want an email sent to me with some info; it's not necessarily happening on an Exception.
If I do something like this:
logger.error("fee did not exist in the database for action %s", "actionX")
The information in the logfile is fine, but the email is really lacking some information. Here's the subject line:
[Django] ERROR: Test this jazz %s
And then the body:
None
Request repr() unavailable
My question is, how do I get A) the value to show up in the subject and B) get some actual, relevant information in the body....like line number or something like that.
You need to acknowledge two things:
Anyways, not impossible!
...that stuff is merged into your settings.
Then, there's your special logging class, MyEmailHandler:
Now you're able to create a special logging entry that's both emailed and output to the terminal this way:
and to make stuff easy, use a utility function:
The Django Logging docs state:
You need to tweak your settings in your logging.config() dictionary. That allows you to set out exactly what information you want and how to format.
Cutting a small bit from the docs:
Gives you a bit of an idea how you can influence the output, and the logging.config docs for python will fill out the available options.