简体   繁体   English

Python-如何使日志文件不可见并将其发送到我的电子邮件

[英]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.

相关问题 如何使 python 中没有簇质心的簇不可见? - How can i make invisible the clusters without cluster centroid in python? 如何在python中获取从电子邮件接收/发送的日期 - How can I get the date recieved / sent from email in python 我如何知道Django / Python是否正确发送了电子邮件? - How can I know if a email is sent correctly with Django/Python? 如何让我的 Python Discord 机器人检查消息是否由机器人本身发送? - How can make my Python Discord bot I check if a message was sent by the bot itself? 如何切换到我在 logging.ini 文件中定义的 Python 日志格式化程序? - How do I switch to a Python log formatter I have defined in my logging.ini file? 如何在 Python 中跟踪日志文件? - How can I tail a log file in Python? 如何在每封电子邮件发送后让代码暂停 5 秒 - How can I make the code pause 5 seconds after every email sent 我如何使用我的 json 文件中的数据来使脚本工作? - how can i use the data i have in my json file to make the script work? 当进程被终止时,如何在 Python 中保存我的日志文件 - How can I save my log file in Python when the process is killed 如何在Outlook“已发送邮件”文件夹中看到使用Python的smtplib发送的电子邮件? - How can I see emails sent with Python's smtplib in my Outlook Sent Items folder?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM