【问题标题】:django celery how to print or check logging for the taskdjango celery 如何打印或检查任务的日志记录
【发布时间】:2018-09-22 14:46:23
【问题描述】:

我现在可以使用 django 和 celery。但是我没有打印日志来检查任务是否正常工作。我正在使用 mac 并计划在我的 ubuntu aws 机器上使用 celery。

这是我在 tasks.py 中所做的:

import string
from celery import shared_task
import logging
@shared_task
def send_push_notification_celery(total):
    logging.debug("send_push_notification_celery")
    logging.debug("total:%d", total)
    return "i love you"

这就是在 celery worker 控制台上打印出来的全部内容:

[2018-04-12 11:25:08,620: INFO/MainProcess] Received task: myapp.tasks.send_push_notification_celery[322eae85-3ef7-4adb-b3bd-eae90300587b]  
[2018-04-12 11:25:08,622: INFO/ForkPoolWorker-2] Task myapp.tasks.send_push_notification_celery[322eae85-3ef7-4adb-b3bd-eae90300587b] succeeded in 0.0001755820121616125s: 'i love you'

【问题讨论】:

  • 您的日志记录是否设置为实际呈现debug 级别的消息?

标签: python django logging celery


【解决方案1】:

您可以使用普通 python print 将数据从 celery 任务输出到控制台:

def send_push_notification_celery(total):
    print("send_push_notification_celery")
    print("total:%d", total)
    return "i love you"

【讨论】:

    猜你喜欢
    • 2020-08-04
    • 2013-09-30
    • 2015-12-25
    • 2012-11-02
    • 2014-05-22
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    • 2019-01-04
    相关资源
    最近更新 更多