#125: Logging in Celery
Errors happen, especially when you have a distributed application. Let's look how Celery allows us to log messages into the Celery logger.
Get the logger
Celery uses the standard Python logger library, what means we can work with the logger as described in my Python Friday post #62. The only special thing to do is to get the logger from Celery instead of creating a new one:
If we use the Celery logger our messages automatically get the name of the task and the unique id:
If our task runs it will write a message like this one:
[INFO/MainProcess] celery_task.prepare[b3a376ad-0f27-4fe2-8b28-e4f94c013096]: order #22 prepared
That may help you a lot more to map your log entry to the other things that go on in Celery. As a comparison, the print() statement got us this log entry:
[WARNING/MainProcess] order #20 prepared
Next
We now have the most important parts together. Next week we have a look how to use Celery with a Flask application.