[英]Python - How can I make a log file invisible and have it sent to my Email
So i created a logger and it saves the log file to wherever the .pyw file is and i was wondering if i could make it save the log file at a different location or make it invisible. 因此,我创建了一个记录器,它将日志文件保存到.pyw文件所在的位置,我想知道是否可以使它将日志文件保存在其他位置或使其不可见。 I'm thinking that it would be better to save it at a different location since I want to send the log file to my Email every 15-20 minutes.
我认为最好将其保存在其他位置,因为我想每15-20分钟将日志文件发送到我的电子邮件中。 Using Python 2.7.8
使用Python 2.7.8
Assuming you used the logging module from standard library, you can change the location of this log file like this: 假设您使用了标准库中的日志记录模块,则可以这样更改日志文件的位置:
import logging
logging.basicConfig(filename='<full-location-here>',level=logging.DEBUG)
For making the file invisible, on a UNIX system you can always make the filename start with a '.' 为了使文件不可见,在UNIX系统上,您始终可以使文件名以“。”开头。 or if you're on windows, may be you can use third-party modules like pywin32 to achieve the same (I am not sure about this part though).
或者如果您使用的是Windows,则可以使用pywin32之类的第三方模块来实现相同的功能(不过我不确定这部分内容)。
Or alternatively, you can use tempfile library to create a temporary file like object and send it. 或者,您可以使用tempfile库来创建一个类似于object的临时文件并将其发送。 For sending the mail, use a module like smtplib .
要发送邮件,请使用smtplib之类的模块。
Also, read the docs. 另外,请阅读文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.