Created
February 17, 2021 04:51
-
-
Save slee981/257a6525734a0aef1848062f1967e290 to your computer and use it in GitHub Desktop.
Python Logging Example
This file contains 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 | |
# potential levels to log (hierachy): | |
# - DEBUG : everything | |
# - INFO : everything except debug | |
# - WARN : warn or error | |
# - ERROR : only error | |
# e.g. handle error in "try / except" block | |
# | |
# CHANGE THIS!!!! | |
logging.basicConfig(level=logging.DEBUG) | |
# start info | |
logging.info("start program") | |
# do something you want to debug | |
logging.debug("start tricky thing") | |
# if something weird hits, send warning | |
weird_situation = True | |
if weird_situation: | |
logging.warning("maybe a mistake!") | |
# finish something you want to debug | |
logging.debug("end tricky thing") | |
# end info | |
logging.info("end program") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very nice, thank you!