code: def log_last_error(fname, context=None):
      
      fd = open(fname, 'a')
      log_time(fd)
      if context:
          print("Context", file=fd)
          print("-------", file=fd)
          print("", file=fd)
          if PY2:
              print(u' '.join(context).encode('utf-8').strip(), file=fd)
          else:
              print(context, file=fd)
          print("", file=fd)
          print("Traceback", file=fd)
          print("---------", file=fd)
          print("", file=fd)
      traceback.print_exc(file=fd)
      print("", file=fd)
      print("", file=fd)
docs: Log last error in filename *fname* -- *context*: string (optional)