I’ve been wanting to make my exception e-mails a bit easier to read / navigate and I think that if I could color code the output, noticeably the traceback and some JSON prints, it would make my life much easier.
So this question is twofold:
-
How can I setup my formatter for my
SMTPHandlerso that it spits out HTML, and have theSMTPHandlersend the e-mails as HTML and not just plain text? -
Do you know of any libraries that would make it easy to take tracebacks and/or JSON and color code the output into HTML?
This solutions extends standard logging.SMTPHandler and uses
pygmentslibrary to create colorful html version of traceback. It’s not very elegant, because it has to use formatter private attribute:_fmtto construct additional log information, but it works (you can customize styles using pygments or directly in html variable):Edit: You can also use my logging handler from my fork of great-justice: https://github.com/paluh/great-justice-with-logging/blob/master/great_justice/logging.py#L85
It generates really nice, informative traceback – the same format is used in emails and in terminal handler: