如何在文件中写入日志? [英] How do I write logs in a file?

查看:71
本文介绍了如何在文件中写入日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的python代码中使用了httplib并提到了以下内容。





 import httplib 

httplib.HTTPConnection.debuglevel = 2







我得到所有信息我需要,但httplib库正在控制台上打印它。我不知道我可以通过哪种方式获取所有这些日志文件而不是控制台。



我们的帮助表示赞赏。

解决方案

如果 HTTPConnection 没有定义的方法写入文件,那么你需要重定向 stdout ,如在Python中重定向各种stdout中所述 - Eli Bendersky的网站 [ ^ ]。

I am using httplib in my python code and have following mentioned.


import httplib

httplib.HTTPConnection.debuglevel = 2




I do get all the info I need but httplib library is printing it on console. I do not know any way by which I can get all those logs in file and not on console.

Your help is appreciated.

解决方案

If HTTPConnection does not have a defined method to write to a file, then you would need to redirect stdout, as described in Redirecting all kinds of stdout in Python - Eli Bendersky's website[^].


这篇关于如何在文件中写入日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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