跑步时看不到我的芹菜原木

时间:2013-11-12 05:04:52

标签: python logging celery supervisord

我通过supervisord开始芹菜,请参阅下面的条目。

[program:celery]
user = foobar
autostart = true
autorestart = true
directory = /opt/src/slicephone/cloud
command = /opt/virtenvs/django_slice/bin/celery beat --app=cloud -l DEBUG -s /home/foobar/run/celerybeat-schedule --pidfile=/home/foobar/run/celerybeat.pid
priority = 100
stdout_logfile_backups = 0
stderr_logfile_backups = 0
stdout_logfile_maxbytes = 10MB
stderr_logfile_maxbytes = 10MB
stdout_logfile = /opt/logs/celery.stdout.log
stderr_logfile = /opt/logs/celery.stderr.log

pip冻结| grep芹菜

celery==3.1.0

但任何用法:

@celery.task
def test_rabbit_running():
    import logging
    from celery.utils.log import get_task_logger
    logger = get_task_logger(__name__)
    logger.setLevel(logging.DEBUG)
    logger.info("foobar")

未显示在日志中。相反,我得到如下条目。

celery.stdout.log

celery beat v3.1.0 (Cipater) is starting.
__    -    ... __   -        _
Configuration ->
    . broker -> redis://localhost:6379//
    . loader -> celery.loaders.app.AppLoader
    . scheduler -> celery.beat.PersistentScheduler
    . db -> /home/foobar/run/celerybeat-schedule
    . logfile -> [stderr]@%DEBUG
    . maxinterval -> now (0s)

celery.stderr.log

[2013-11-12 05:42:39,539: DEBUG/MainProcess] beat: Waking up in 2.00 seconds.
INFO Scheduler: Sending due task test_rabbit_running (retail.tasks.test_rabbit_running)
[2013-11-12 05:42:41,547: INFO/MainProcess] Scheduler: Sending due task test_rabbit_running (retail.tasks.test_rabbit_running)
DEBUG retail.tasks.test_rabbit_running sent. id->34268340-6ffd-44d0-8e61-475a83ab3481
[2013-11-12 05:42:41,550: DEBUG/MainProcess] retail.tasks.test_rabbit_running sent. id->34268340-6ffd-44d0-8e61-475a83ab3481
DEBUG beat: Waking up in 6.00 seconds.

如何让我的日志记录调用显示在日志文件中?

2 个答案:

答案 0 :(得分:4)

它不记录任何内容,因为它不执行任何任务(并且没关系)。

另见Celerybeat not executing periodic tasks

答案 1 :(得分:0)

我尝试将调用记录在任务中,因为util函数的名称意味着get_task_logger,或者只是以简单的打印开始,或者按照Django Celery Logging Best Practice中的建议设置自己的日志(去IMO的最佳方式)