code: def log(fn, opts, task, *args, **kwargs):
      
      _task = get_task(task)
      log = get_param(_task.log_file, _task.default_log_file)
  
      if log == "-" or not log:
          return fn(task, *args, **kwargs)
      else:
          # use the local target functionality to create the parent directory
          LocalFileTarget(log).parent.touch()
          with open_compat(log, "a", 1) as f:
              tee = TeeStream(f, sys.__stdout__)
              sys.stdout = tee
              sys.stderr = tee
              try:
                  ret = fn(task, *args, **kwargs)
              except:
                  traceback.print_exc(file=tee)
                  raise
              finally:
                  sys.stdout = sys.__stdout__
                  sys.stderr = sys.__stderr__
                  tee.flush()
          return ret
docs: log()
      Wraps a bound method of a task and redirects output of both stdout and stderr to the file
      defined by the tasks's *log_file* parameter or *default_log_file* attribute. If its value is
      ``"-"`` or *None*, the output is not redirected.