Skip to content

Instantly share code, notes, and snippets.

@slee981
Created February 17, 2021 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slee981/257a6525734a0aef1848062f1967e290 to your computer and use it in GitHub Desktop.
Save slee981/257a6525734a0aef1848062f1967e290 to your computer and use it in GitHub Desktop.
Python Logging Example
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")
@ssordopalacios
Copy link

Very nice, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment