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:
[handlers]Once everything is setup, you can add calls like the following to your controllers:
-keys = console
+keys = console, smtp
[formatters]
keys = generic
[logger_root]
level = INFO
-handlers = console
+handlers = console, smtp
[handler_console]
class = StreamHandler
@@ -67,5 +67,11 @@
level = NOTSET
formatter = generic
+[handler_smtp]
+class = logging.handlers.SMTPHandler
+args = ('127.0.0.1', 'myapp@localhost', ['sendto@example.com'], 'myapp log message')
+level = WARN
+formatter = generic
+
log.error("This is a test of the logging system.")
Comments
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 :)