Python logging split between stdout and stderr [duplicate]
问题 This question already has answers here : How can INFO and DEBUG logging message be sent to stdout and higher level message to stderr (7 answers) Closed 6 years ago . Is it possible to have python logging messages which are INFO or DEBUG to go to stdout and WARNING or greater to go to stderr? 回答1: This seems to do what I want: #!/usr/bin/python import sys import logging class InfoFilter(logging.Filter): def filter(self, rec): return rec.levelno in (logging.DEBUG, logging.INFO) logger = logging