I am trying to create a simple handler in my app that would inform me if there’s a problem in my scripts (think of it as a very simple notification version of Sentry).
In the __init__.py
file, I set this code:
import logging
import logging.handlers
smtp_handler = logging.handlers.SMTPHandler(mailhost=("smtp.gmail.com", 587),
fromaddr="[email protected]",
toaddrs="[email protected]",
subject="EXCEPTION",
credentials=('[email protected]', 'my_password'),
secure=())
a = logging.getLogger('sreality')
a.setLevel(logging.DEBUG) # set root's level
smtp_handler.setLevel(logging.ERROR)
a.addHandler(smtp_handler)
To test it out, I put into my code a non-existing variable that caused an error (visible in terminal):
NameError: name 'xresponse' is not defined
My expectation was that I would receive an email with NameError: name 'xresponse' is not defined
(and ideally the traceback) to my inbox. However – that did not happen.
What am I overlooking? The whole purpose of it is to be notified when there’s an error that’s preventing the program to finish.