Skip to content

Instantly share code, notes, and snippets.

@saintsGrad15
Last active March 8, 2023 23:37
Show Gist options
  • Select an option

  • Save saintsGrad15/45da9626f634870835260640cf59cbce to your computer and use it in GitHub Desktop.

Select an option

Save saintsGrad15/45da9626f634870835260640cf59cbce to your computer and use it in GitHub Desktop.
The very most basic logging setup for Python
import logging
import sys
# Use this format for more verbosity
LOGGING_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(stream=sys.stdout)
handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT))
# Only necessary if the same code is being run multiple times as in a notebook, for instance.
if len(logger.handlers) > 0:
logger.handlers = []
logger.addHandler(handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment