The two methods output by using the python logging module in stdout are described in detail.
Use the logging module of python to output data in stdout
Preface:
When using the python logging module, in addition to logging logs in files, you also want to directly output logs to the standard output std. out when running the python script on the foreground.
Implementation
The logging module can implement this function in two ways:
Solution 1: basicconfig
Import sysimport logginglogging. basicConfig (stream = sys. stdout, level = logging. DEBUG)
Solution 2: handler
Logging can add multiple handler, so you only need to add an additional handler to the log.
Import sysimport logginglog = logging. getLogger () stdout_handler = logging. StreamHandler (sys. stdout) log. addHandler (stdout_handler)
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!