Skip to content

Instantly share code, notes, and snippets.

@yalattas
Last active October 10, 2023 13:50
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 yalattas/72a5df4635fd0cf52a704d3aebee1086 to your computer and use it in GitHub Desktop.
Save yalattas/72a5df4635fd0cf52a704d3aebee1086 to your computer and use it in GitHub Desktop.
python
import logging

# create a new logger
logger = logging.getLogger('main')

# set logger level
logger.setLevel(logging.DEBUG)

# stream log into console by creating a handler
stream_handler = logging.StreamHandler()

# add handler formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
stream_handler.setFormatter(formatter)

# assign formatter to handler
logger.addHandler(stream_handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment