@contextlib.contextmanager
def task_logging(task):
 old_task = getattr(local_context, u'task', u'')
 local_context.task = task
 try:
  (yield)
 finally:
  local_context.task = old_task

@ contextlib . contextmanager def task_logging ( task ) : old_task = getattr ( local_context , u'task' , u'' ) local_context . task = task try : ( yield ) finally : local_context . task = old_task
context manager which adds task information to log messages .