Uncategorized

Loging best practices with Python

Python logging

I want to share my approach to logging in Python.

Logging is very important. This helps debug your apps avoiding headache. It can help you understand how the flow of a program works.

Please note, it can send email when an exceptions is raised.

A custom class inherits from logging.handlers.BufferingHandler in order to get mail sent, and overrides flush method to send mail via SMTP.

You cant spaming your own mail with debug trace, so you can set the levels on you want to inform via yaml configuration. Tip: Set the mail handler to error level, so you can get warn when app crashes.

https://github.com/cvalienteDS/custom_logging_python

References:

https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/

https://realpython.com/python-logging/

https://gist.github.com/anonymous/1379446

https://stackoverflow.com/questions/46160886/how-to-send-smtp-email-for-office365-with-python-using-tls-ssl

https://gist.github.com/kingspp/9451566a5555fb022215ca2b7b802f19

Leave a Reply

Your email address will not be published. Required fields are marked *