python-daemon不记录标准输出重定向 [英] python-daemon not logging stdout redirection

查看:117
本文介绍了python-daemon不记录标准输出重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码中使用python-daemon,其中包含打印语句。我想将它们发送到文件,因此我运行了以下命令:

I am using python-daemon in my code that has print statements in it. I want to send them to a file so I ran the following:

python server.py >> log.out

但是, log.out

有人可以告诉我我需要做什么吗?

Can anyone tell me what I need to do?

谢谢。

推荐答案

创建对象时,DaemonContext对象允许重定向stdout / stderr / stdin。例如:

The DaemonContext object allows redirecting stdout/stderr/stdin when you create the object. For example:

import os
import daemon


if __name__ == '__main__':
    here = os.path.dirname(os.path.abspath(__file__))
    out = open('checking_print.log', 'w+')

    with daemon.DaemonContext(working_directory=here, stdout=out):
        for i in range(1, 1000):
            print('Counting ... %s' % i)

您应该能够 catcheck_print.log 并查看打印语句的输出。

You should be able to cat checking_print.log and see the output from the print statements.

DaemonContext对象的良好参考是 PEP 3143

A good reference for the DaemonContext object is PEP 3143.

这篇关于python-daemon不记录标准输出重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆