简体   繁体   English

当执行包含日志记录的python脚本时,popen返回错误

[英]popen returns error when executing python script containing logging

I have 2 python scripts where 1 is using subprocess to execute the other, see below: 我有2个python脚本,其中1个正在使用子进程执行另一个,请参见下文:

main.py main.py

import subprocess

command = ['python', 'logging_test.py']
proc1 = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

out, err = proc1.communicate()

print('Output returned from command: {}'.format(out))
print('Error returned from command: {}'.format(err))

logging_test.py logging_test.py

import logging

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('log')
logger.info('hello')

When running main.py I get this as the output: 运行main.py时,将其作为输出:

Output returned from command:
Error returned from command: INFO:log:hello

I would expect for the log message to be returned by stdout, not stderr... Does anyone know why it is getting returned as an error? 我希望日志消息由stdout而不是stderr返回...有人知道为什么它作为错误返回吗?

basicConfig , among other things, provides a StreamHandler for the root logger . 除其他外, basicConfig 为根logger提供了一个StreamHandler By default, a new StreamHandler writes to standard error . 默认情况下, 新的StreamHandler写入标准error

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM