Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python Logging with a decent format
import logging
log = logging.getLogger()
log.setLevel(logging.INFO)
log_handler = logging.StreamHandler()
log_formatter = logging.Formatter(
"[%(levelname)s] %(asctime)s.%(msecs)03d line:%(lineno)d %(funcName)s %(message)s",
style="%",
datefmt="%Y-%m-%dT%H:%M:%S")
log_handler.setFormatter(log_formatter)
log.addHandler(log_handler)
log.info("This is a journey into test")
def testing_log():
log.info("Where is this logged from?")
testing_log()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.