Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django celery how to print or check logging for the task

I have now got django and celery working. but there is no logs print for me to check if the task is working correctly. I am using mac and plan to use celery on production in my ubuntu aws machine.

Here is what i do in 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"

this is all that gets printed out on celery worker console:

[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'
like image 562
Axil Avatar asked Feb 02 '26 00:02

Axil


1 Answers

You can use normal python print to output data into console from celery task:

def send_push_notification_celery(total):
    print("send_push_notification_celery")
    print("total:%d", total)
    return "i love you"
like image 156
neverwalkaloner Avatar answered Feb 03 '26 12:02

neverwalkaloner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!