[英]Scheduled cron Python script logging working differently than it does when run manually
I have a Python script that is running as a cron job every day.我有一个 Python 脚本,它每天都作为 cron 作业运行。 I'm trying to get it to only output when necessary so that cron doesn't email me unless there is a warning or error.
我试图在必要时仅将其设置为 output 以便 cron 不会 email 我,除非有警告或错误。 However, DEBUG-level output is still being emailed to me, even though I've set the logging level to WARNING.
然而,调试级别的 output 仍在通过电子邮件发送给我,即使我已将日志记录级别设置为警告。
import logging
logging.basicConfig(level=logging.WARNING)
When I run the script through IDLE this works as intended with no output.当我通过 IDLE 运行脚本时,它按预期工作,没有 output。 (If I omit those two lines, I get a bunch of DEBUG output).
(如果我省略这两行,我会得到一堆 DEBUG 输出)。 But when the script runs through the cron schedule, I'm being emailed those DEBUG lines.
但是当脚本通过 cron 计划运行时,我会收到那些 DEBUG 行的电子邮件。
My crontab is simple:我的 crontab 很简单:
DISPLAY=:0.0
0 6 * * * python3 /home/pi/script.py
Any ideas?有任何想法吗?
I figured it out.我想到了。 I was setting the default logging level after importing the module that was automatically generating that debug output.
在导入自动生成调试 output 的模块后,我设置了默认日志记录级别。 Kind of obvious now.
现在有点明显了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.