在芹菜中使用Python标准日志记录 [英] Use Python standard logging in Celery
问题描述
我的代码与下面的代码类似。过程一和过程二是非Celery函数,它们在任何地方进行日志记录。我们正在使用日志跟踪数据丢失,如果发生不好的事情。
@task
def add(x,y )
process_one(x,y)
process_two(x,y)
如何实现Celery并使用Python标准日志记录,而不是使用Celery日志记录,因此我们的旧日志记录系统不会丢失?
我已经尝试更改到
logger = add.get_logger()
并传递 logger
所有的功能,但我不认为这是一个很好的做法。我需要另一个解决方案。
更新:在Celery日志记录中添加应用程序日志记录,可以执行以下操作:
$ manage.py celeryd -v 2 -B -s celery -E -l debug --traceback \
--settings = settings --logfile = /(路径到你的日志文件夹)/celeryd.log
With l
(logging)as debug
,我们的应用程序/ Python日志记录自动包含在我们的Celery日志中:不需要执行 logger = add.get_logger()
。
你可能想要这个设置:
CELERYD_HIJACK_ROOT_LOGGER = False
告诉我如何工作。
Btw,它劫持根记录器的原因是因为一些写得不好的
库设置了日志记录,一个库应该永远不会,导致用户体验没有输出celeryd
工作:(
I have to implement Celery in a pre-existing system. The previous version of the system already used Python standard logging.
My code is similar to the code below. Process one and process two are non-Celery functions, which are logging everywhere. We are using the logging to track data loss if something bad happens.
@task
def add(x,y):
process_one(x,y)
process_two(x,y)
How can I implement Celery and use the Python standard logging instead Celery logging, so our old logging system is not lost?
I have tried to change import logging
from Python to: logger = add.get_logger()
and pass the logger
to all functions, but I don't think it is a good practice. I need another solution.
Update: to add application logging in Celery logging, you can perform:
$ manage.py celeryd -v 2 -B -s celery -E -l debug --traceback \
--settings=settings --logfile=/(path to your log folder)/celeryd.log
With -l
(logging) as debug
, our application/Python logging is automatically included in our Celery logging: No need to perform logger = add.get_logger()
.
You probably want this setting:
CELERYD_HIJACK_ROOT_LOGGER = False
Tell me how that works out.
Btw, the reason it hijacks the root logger is because some badly written libraries sets up logging, something a library should never do, resulting in users experiencing no output from the celeryd worker :(
这篇关于在芹菜中使用Python标准日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!