1

I have some Python code processing incoming e-mail. In there, there's a function process_mail. While using the logging module from the Python3 stdlib, I would like to be able to send all log entries from one call to process_mail via e-mail to the original sender in case of an error.

So the question is: How can I create temporary, throw-away logger instances at the beginning of my function, and use this to send the log back to the sender, preferably without having to read/filter the log file? At the same time, all entries should go to my normal logs.

gincard
  • 1,814
  • 3
  • 16
  • 24
andreas-h
  • 10,679
  • 18
  • 60
  • 78
  • Is the logging module's [SMTPHandler](https://docs.python.org/3.5/library/logging.handlers.html#smtphandler) what you're looking for, by any chance? – deepbrook Jan 10 '17 at 12:59
  • @nlsdfnbch in principle yes, but I cannot figure out how to group log messages into one single email and not send a mail each time the logger is used. – andreas-h Jan 10 '17 at 16:16
  • create a logger within the function, attach a separate `FileHandler` and pass that file's path to `process_mail` and send via attachment? – deepbrook Jan 11 '17 at 10:36
  • I had a similar issue this provided me with hints https://stackoverflow.com/questions/17035077/logging-to-multiple-log-files-from-different-classes-in-python – Sheece Gardazi Jun 26 '18 at 01:24

0 Answers0