Python.将stderr重定向到日志文件 [英] Python. Redirect stderr to log file

查看:91
本文介绍了Python.将stderr重定向到日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Django网站处理龙卷风和nginx.

I have Django web-site working on tornado and nginx.

我拿了这个龙卷风发射器脚本(tornading.py)

I took this tornado launcher script (tornading.py)

然后,我使用的是python openid,它会将一些信息输出到sys.stderr.

Then I'm using python openid that outputs some information to sys.stderr.

结果我得到IOError.

As a result I get IOError.

如何使用日志记录包将其重定向?

How can I redirect it using logging package?

我考虑过

f = open("myfile.log", "w")
sys.stderr = f

python tornado.py > /dev/null 2>&1

但是解决它的最好方法是什么?

But what is the best way to solve it?

推荐答案

最好的方法是,如果openid库没有打印到stderr,而是使用了某种日志记录API(例如,日志记录模块).我同意thkala的观点,从长远来看,修改第三方代码是不好的,因此您应该对其进行修复,然后将其提供给openid作者.

The best way would be if the openid library didn't print to stderr, but used some kind of logging API instead (e.g. the logging module). I agree with thkala that modifying third-party code is not good in the long term, so you should fix it, and then provide the fix to the openid authors.

为了发展开源社区,这是解决它的最好方法.

For the objective of advancing the open source community, that's the best way to solve it.

这篇关于Python.将stderr重定向到日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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