Created
January 4, 2021 10:32
-
-
Save pietrocolombo/ac610d9121f90e086a955b5852554a86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import logging.handlers | |
# Enable logging | |
logging.basicConfig( | |
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', | |
level=logging.INFO, filename='log.log') | |
logger = logging.getLogger(__name__) | |
smtp_handler = logging.handlers.SMTPHandler(mailhost=('smtp.gmail.com', 587), | |
fromaddr='email', | |
toaddrs=['email_1', | |
'email_2'], | |
subject='Error', | |
credentials=( | |
'email', | |
'password_App'), | |
secure=()) | |
logger.addHandler(smtp_handler) | |
def error(err_name, err): | |
"""Log Errors""" | |
logger.warning('error "%s" caused error "%s"', err_name, err) | |
def main(): | |
print("Hi") | |
try: | |
a = 10/0 | |
except ZeroDivisionError as err: | |
error('Handling run-time error:', err) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment