Anyway, the shortest way I could find of setting this up (debug
silenced, info written to stdout, warning and above written to
stderr):
import sys, logging
root = logging.getLogger()
# Turns out the level of the root logger is set to WARNING by default
# That should be much easier to find out from the logging docs!
root.setLevel(logging.DEBUG)
# Send WARNING and above to stderr
# basicConfig() is no help, since it sets the specified level on the
root logger
# but NOT on the default handler it installs. To emulate console output
# we want to skip the formatting anyway.
err = logging.StreamHandler()
err.setLevel(logging.WARNING)
root.addHandler(err)
# Send INFO to stdout
def is_info(record):
return record.levelno == logging.INFO
out = logging.StreamHandler(stream=sys.stdout)
out.addFilter(is_info)
root.addHandler(out)