[Tutor] Best way to use excepthook here?
Peter Otten
__peter__ at web.de
Fri Jun 24 14:27:09 EDT 2016
Alex Hall wrote:
> One related question. This more of a style choice, I know, but I'd like
> anyone's thoughts all the same. Currently, in my ADLogger.logExceptions
> function, I log the exception (obviously). But I also take the opportunity
> to generate and send an email, warning that the job raised an exception
> and attaching the log file as well as printing the traceback in the email.
> Loggers generally just log, and it feels kind of hacky to include email
> code in a function that primarily logs exceptions. At the same time, this
> is a perfect place to do it, because it gets called if an exception is
> raised, and if that happens, the job almost certainly failed so I need to
> know about it. I don't know of another way to do this since I don't have a
> Python-based central manager, so can't examine exit codes or anything
> else.
Sending emails should be the concern of a handler, not a logger.
https://docs.python.org/dev/library/logging.handlers.html#smtphandler
More information about the Tutor
mailing list