我使用记录器打印出标准输出和标准错误来记录文件。我已经这样做了:
def log(process):
logger = logging.getLogger('logging_errors')
if not len(logger.handlers):
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(levelname)s %(asctime)s %(module)s %(message)s')
handler_stderr = logging.FileHandler('stderr.log')
handler_stderr.setLevel(logging.WARNING)
handler_stderr.setFormatter(formatter)
logger.addHandler(handler_stderr)
handler_stdout = logging.FileHandler('stdout.log')
handler_stdout.setLevel(logging.DEBUG)
handler_stdout.setFormatter(formatter)
logger.addHandler(handler_stdout)
return logger.error(process.stderr.read())
return logger.info(process.stdout.read())
一个进程被传递给这个函数,它可以是这样的:
proc = subprocess.Popen(['FastTree -nt test.fasta'], stdin = None, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell=True)
proc.wait()
log(proc)
我遇到的问题是stdout 没有打印到stdout.log 文件中,我在stdout.log 文件中得到了stderr。stderr.log 文件是正确的。对此有任何指示吗?