【发布时间】:2019-10-02 19:48:10
【问题描述】:
我有一个非常简单的测试设置,其中包含 cron 和一个使用 logging 模块的 Python 脚本,而 cron 在遇到日志事件时表现异常。
crontab
* * * * * ~/test.py >> ~/test.log
~/test.py
>#!/usr/bin/env python
import logging
logging.basicConfig(level=logging.DEBUG)
print 'Properly printed, to file'
logging.debug("Does not get printed, get's e-mailed as an error")
print 'Still running, though'
~/test.log
cron 运行后,日志中会填充以下两条消息:
Properly printed, to file
Still running, though
cron 错误邮件
另外,在 cron 运行后,我收到一条通知说我有新邮件:
From tomcat6@local Thu May 23 16:35:01 2013
Date: Thu, 23 May 2013 16:35:01 -0700
From: root@local (Cron Daemon)
To: tomcat6@local
Subject: Cron <tomcat6@local> ~/test.py >> ~/test.log
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/usr/local/tomcat6>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=tomcat6>
X-Cron-Env: <USER=tomcat6>
DEBUG:root:Does not get printed, get's e-mailed as an error
看起来这不是一个明确的错误,否则最终的“仍在运行...”消息将不会打印到~/test.log,对吧?
为什么 cron 和/或日志记录会这样做,是否有解决方法?
【问题讨论】: