Skip to content

Instantly share code, notes, and snippets.

@lyrick17
Created July 16, 2023 08:11
Show Gist options
  • Save lyrick17/9103db10c2e36fda93c7657eb4ee33fc to your computer and use it in GitHub Desktop.
Save lyrick17/9103db10c2e36fda93c7657eb4ee33fc to your computer and use it in GitHub Desktop.
logging codes for Python, useful for debugging
# This is set up code for logging in Python
# - the format can be changed
import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
# this is the set up instead if you want to save the logs in another file
logging.basicConfig(filename="filename.txt", level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
# Disable all the logs...(will be used to stop the logs)
# - you can change CRITICAL into DEBUG, WARNING, INFO, ERROR, CRITICAL
# depending on log level you want to disable
# - where CRITICAL is highest log level
logging.disable(logging.CRITICAL)
# Comment this code if you don't want the logs to appear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment