For making Python loggers output all messages to stdout in addition to the log file you can use the following method which is using logging and sys module to :
import logging
import sys
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
One thing to note that all the logging output is handled by the handlers, you just need to add logging.StreamHandler() to the logger which is root.
Below is an example that is using stdout instead of the default stderr and also adding it to the root logger.
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)
For more information, kindly refer to our Python course.