Python-Celery:如何读取其他模块记录的日志信息

时间:2019-07-03 19:59:29

标签: python logging celery

我有一个芹菜任务operation,如下所示:

# tasks.py

@app.task(bind=True, name='operation')
def operation(self, request):
    custom_library = CustomLibrary()
    res = custom_library.foo(request)
    return res

如上面的代码片段所示,celery任务调用自定义库函数custom_library.foo()。函数foo()使用Python logging记录一些信息,例如以"PROGRESS %58"格式的进度百分比:

# custom_library.py

class CustomLibrary:
    # __init__() and all other methods are removed here for readability
    def foo(request):
         # There were some things being done here that are removed for readability
         logging.info("PROGRESS %58") # This is just an example. The progress is updated dynamically.

芹菜任务由另一个模块中的manage()函数调用,如下所示:

   # scheduler.py

   def manage(request):
       operation.s(request).apply_async()

   def get_logging_info():
       # get all info from Python logging and return

现在,我想拥有一个get_logging_info()函数,该函数能够访问PROGRESS函数记录的custom_library.foo()信息。

任何帮助将不胜感激!

0 个答案:

没有答案