Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 是否可以控制芹菜任务日志的datefmt?_Python_Logging_Celery - Fatal编程技术网

Python 是否可以控制芹菜任务日志的datefmt?

Python 是否可以控制芹菜任务日志的datefmt?,python,logging,celery,Python,Logging,Celery,使用普通python记录器,您可以如下配置格式字符串和日期格式: { 'format': '%(asctime)s.%(msecs)d [%(process)d] %(levelname)s [%(name)s] %(message)s',

使用普通python记录器,您可以如下配置格式字符串和日期格式:

{                                                                                                     
    'format': '%(asctime)s.%(msecs)d [%(process)d] %(levelname)s [%(name)s] %(message)s',                       
    'datefmt': %d/%m/%Y-%H:%M:%S'                                                                              
}
但我完全无法找到任何方法将
datefmt
传递给芹菜任务记录器。这似乎是一个基本的功能,如果不可能的话,我会感到惊讶

我得到的最接近的方法是遵循。其要点是使用
after\u setup\u task\u logger
信号自定义记录器处理程序,以传递自定义
TaskFormatter
。但诀窍在于,虽然
TaskFormatter
让您传递一个格式字符串,但它似乎没有任何允许您传递
datefmt
的规定

这似乎得到了芹菜github上的研究的证实


那么,有什么明显的东西我遗漏了吗?不必等待芹菜就能解决上述问题的技巧?真的不可能吗?

在创建任务格式化程序后,可以通过设置datefmt属性来设置datefmt。的
\uuuu init\uuuu
正是这样做的

tf = TaskFormatter('%(asctime)s.%(msecs)d [%(process)d] %(levelname)s [%(name)s] %(message)s')
tf.datefmt = '%d/%m/%Y-%H:%M:%S' 
handler.setFormatter(tf)

我应该指出的是,如果芹菜可以解决问题,我愿意升级芹菜,但我使用的是4.2.1版,我更喜欢不需要升级的解决方案。