16 lines
		
	
	
		
			365 B
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			16 lines
		
	
	
		
			365 B
		
	
	
	
		
			Python
		
	
	
	
| from celery import Task
 | |
| import logging
 | |
| 
 | |
| # 实例化myLogger
 | |
| myLogger = logging.getLogger('log')
 | |
| 
 | |
| 
 | |
| class CustomTask(Task):
 | |
|     """
 | |
|     自定义的任务回调
 | |
|     """
 | |
| 
 | |
|     def on_failure(self, exc, task_id, args, kwargs, einfo):
 | |
|         myLogger.error('{0!r} failed: {1!r}'.format(task_id, exc))
 | |
|         return super().on_failure(exc, task_id, args, kwargs, einfo)
 |