35

Can someone please help and tell me how to get the celery task debug details to a log file? I have a requirement to have the details of celery task logged into a .log file.

Can you please make some suggestions on how this can be done without impacting the performance of the task?

Leukonoe
  • 649
  • 2
  • 10
  • 29
user2479840
  • 477
  • 1
  • 7
  • 14

2 Answers2

54

Celery have specific option -f --logfile which you can use:

-f LOGFILE, --logfile=LOGFILE
                    Path to log file. If no logfile is specified, stderr
                    is used.

To get information about other options, just use celery worker --help. If just want want celery worker with logging to file, your command may look like this:

celery worker -f <filename>
python manage.py celery worker -f <filename> -> in django-celery case

There are a lot of logging options for Celery you may need: http://docs.celeryproject.org/en/latest/userguide/tasks.html#logging

david.barkhuizen
  • 5,239
  • 4
  • 36
  • 38
Artem Mezhenin
  • 5,539
  • 6
  • 32
  • 51
  • 1
    Thanks a lot for the reply,it was my bad that i didn't explain in details.I have my celery working running,for me I need separate logs to be written on the worker tasks and also in the code that invokes the task. Will writing the logs have performance impact. – user2479840 Jun 29 '13 at 21:02
  • 1
    @user2479840, you can separate logs by configuring loggers to different files http://docs.python.org/2/library/logging.config.html .Perfomance impact is minor, unless you are writing 100K logs in a minute. – Artem Mezhenin Jun 30 '13 at 05:29
  • The above answer is nice. But in addition to that, you can configure the log file in the python project itself using `logging` module –  Jan 24 '22 at 13:28
15

If you want to log everything, you can use the following command

-f celery.logs

You can also specify different log levels as well. For suppose if you want log warning and errors add like following.

--loglevel=warning -f celery.logs

Raja
  • 165
  • 1
  • 10