Is there a way to make Python logging using the logging module automatically output things to stdout in addition to the log file where they are supposed to go? For example, I’d like all calls to logger.warning, logger.critical, logger.error to go to their intended places but in addition always be copied to stdout. This is to avoid duplicating messages like:
mylogger.critical("something failed")
print("something failed")
All logging output is handled by the handlers; just add a
logging.StreamHandler()to the root logger.Here’s an example configuring a stream handler (using
stdoutinstead of the defaultstderr) and adding it to the root logger: