本文整理汇总了Python中celery.worker.job.TaskWrapper.logger方法的典型用法代码示例。如果您正苦于以下问题:Python TaskWrapper.logger方法的具体用法?Python TaskWrapper.logger怎么用?Python TaskWrapper.logger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.worker.job.TaskWrapper
的用法示例。
在下文中一共展示了TaskWrapper.logger方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test_on_failure
# 需要导入模块: from celery.worker.job import TaskWrapper [as 别名]
# 或者: from celery.worker.job.TaskWrapper import logger [as 别名]
def _test_on_failure(self, exception):
tid = gen_unique_id()
tw = TaskWrapper(mytask.name, tid, [4], {"f": "x"})
try:
raise exception
except Exception:
exc_info = ExceptionInfo(sys.exc_info())
logfh = StringIO()
tw.logger.handlers = []
tw.logger = setup_logger(logfile=logfh, loglevel=logging.INFO)
from celery import conf
conf.CELERY_SEND_TASK_ERROR_EMAILS = True
tw.on_failure(exc_info)
logvalue = logfh.getvalue()
self.assertIn(mytask.name, logvalue)
self.assertIn(tid, logvalue)
self.assertIn("ERROR", logvalue)
conf.CELERY_SEND_TASK_ERROR_EMAILS = False
示例2: test_on_failure
# 需要导入模块: from celery.worker.job import TaskWrapper [as 别名]
# 或者: from celery.worker.job.TaskWrapper import logger [as 别名]
def test_on_failure(self):
tid = gen_unique_id()
tw = TaskWrapper("cu.mytask", tid, mytask, [4], {"f": "x"})
try:
raise Exception("Inside unit tests")
except Exception:
exc_info = ExceptionInfo(sys.exc_info())
logfh = StringIO()
tw.logger.handlers = []
tw.logger = setup_logger(logfile=logfh, loglevel=logging.INFO)
from celery import conf
conf.SEND_CELERY_TASK_ERROR_EMAILS = True
tw.on_failure(exc_info, {"task_id": tid, "task_name": "cu.mytask"})
logvalue = logfh.getvalue()
self.assertTrue("cu.mytask" in logvalue)
self.assertTrue(tid in logvalue)
self.assertTrue("ERROR" in logvalue)
conf.SEND_CELERY_TASK_ERROR_EMAILS = False