Python: Logging to Email in Pylons

I figured out how to get Pylons to send logging messages via email. Note, this is separate of the Paste mechanism which sends email when there is an uncaught exception. Here's a diff of my .ini file:
-keys = console
+keys = console, smtp

keys = generic

level = INFO
-handlers = console
+handlers = console, smtp

class = StreamHandler
@@ -67,5 +67,11 @@
level = NOTSET
formatter = generic

+class = logging.handlers.SMTPHandler
+args = ('', 'myapp@localhost', [''], 'myapp log message')
+level = WARN
+formatter = generic
Once everything is setup, you can add calls like the following to your controllers:
log.error("This is a test of the logging system.")


Noah Gift said…
One problem with this email alert stuff is that it grows to become a nuisance. I still wonder why someone hasn't written something that collects email on intervals, based on some smart logic, and then makes a bundle.

For example, if you get 30 uncaught exceptions in 1 minute, one email, with 30 dups is better than 30 emails. I get this a lot in Film, they use email like normal people use the television :)
jjinux said…
To some extent, Gmail does that for me.