python logging info debug warn error code example

Example 1: python logging basicconfig stdout

# https://stackoverflow.com/a/14058475
import logging
import sys

root = logging.getLogger()
root.setLevel(logging.DEBUG)

handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
root.addHandler(handler)

Example 2: python logging

!python -m unittest test_volume_cuboid.py

Tags:

Misc Example