【发布时间】:2016-03-25 16:53:00
【问题描述】:
我目前正在使用 supervisor 来轻松地监控和守护一些 python 脚本。但是,主管似乎无法正确登录。 我正在执行的脚本就这么简单:
#!/usr/bin/env python
import pushybullet as pb
import sys, time, logging
# INIT LOGGING
logging.basicConfig(format='%(asctime)s @%(name)s [%(levelname)s]: %(message)s', level = logging.DEBUG)
if __name__ == '__main__':
try:
logging.info('Custom service started')
while True:
#here for the sake of example, actually doing real stuff here
time.sleep(2)
finally:
logging.info('Custom service stopped')
这里是对应的conf文件:
[program:myscript]
directory=/home/pi/Documents/Scripts_py
command=python -u myscript.py
autostart=true
autorestart=true
所以我根据谷歌上的许多研究测试了很多东西。 通过打印替换日志行然后刷新标准输出确实有效;与启动脚本的 -u 选项相同。但是 print 不能满足我的需要,Python 的 logging 模块可以。因此,我尝试在每个日志记录行之后刷新,并在无缓冲模式中启动脚本,但什么也没有出现!
提前感谢您的帮助!
【问题讨论】:
-
你试过在你的conf文件中指定你想要的日志文件吗?例如:stdout_logfile=/var/log/supervisor/%(program_name)s.log
-
这不是为了指定我们希望主管在哪里输出它自己的程序日志吗?如果是,这对我没有帮助,因为我面临的问题是我的脚本日志根本没有被主管捕获
-
好的,我试了一下,解决了,谢谢!
-
是的,这是正确的(关于文件访问权限),即使您可以在主管 conf 文件中指定 uid:user=youruser
标签: python logging supervisord