Python 芹菜登录到文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17366579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 08:00:22  来源:igfitidea点击:

Celery Logs into file

pythoncelery

提问by user2479840

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.

有人可以帮助并告诉我如何将芹菜任务调试详细信息获取到日志文件中吗?我需要将 celery 任务的详细信息记录到 .log 文件中。

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

您能否就如何在不影响任务性能的情况下完成此操作提出一些建议?

回答by Artem Mezhenin

It's alway hard to answer with so little information in question, but I'll try. Celeryhave specific option -f --logfilewhich you can use:

用这么少的信息来回答总是很困难,但我会尝试。Celery-f --logfile您可以使用的特定选项:

-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 --help. 如果只想让 celery worker 记录到文件,您的命令可能如下所示:

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

您可能需要许多 Celery 日志记录选项:http: //docs.celeryproject.org/en/latest/userguide/tasks.html#logging

回答by Raja

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

如果要记录所有内容,可以使用以下命令

-f celery.logs

-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

--loglevel=警告 -f celery.logs