1

I have working Celery 3.1 app which logs some sensitive info. Ideally I would to have the same log, but without result part.

Currently it looks like:

worker_1 | [2019-12-10 13:46:40,052: INFO/MainProcess] Task xxxxx succeeded in 13.19569299298746s: yyyyyyy

I would like to have:

worker_1 | [2019-12-10 13:46:40,052: INFO/MainProcess] Task xxxxx succeeded in 13.19569299298746s

How to do that?

Edit: It seems that this could do the job: https://docs.celeryproject.org/en/3.1/reference/celery.worker.job.html#celery.worker.job.Request.success_msg but I have no idea how to actually use it.

Damian Melniczuk
  • 393
  • 6
  • 18

3 Answers3

4

Just in case it's useful to anyone in near future, I found in Celery 4.4 the success_msg in the Request class has been moved to the application tracer.

Luckily, it seems this can be easily overridden in your Django app's celery.py like so:

from celery.app import trace

trace.LOG_SUCCESS = """\
Task %(name)s[%(id)s] succeeded in %(runtime)ss\
"""

You can change it to anything you like of course, this just removes the return value portion. Full context here.

Sam Nicholls
  • 861
  • 4
  • 16
0

You need to override the success message being sent, remove the return_value format from there. For that you need to override the Request class, as described here.

You can also override the logging config as mentioned here.

Ayush Pallav
  • 919
  • 9
  • 18
-1

worker_1 | [2019-12-10 13:46:40,052: INFO/MainProcess] Task xxxxx succeeded in 13.19569299298746s: yyyyyyy

yyyyyyy is the result that your function returns, to remove that simply return what you want. in your case only return will work