code: def safe_format(format_string, *args, **kwargs):
      
      try:
          if not args and not kwargs:
              return format_string
          else:
              return format_string.format(*args, **kwargs)
  
      # catch encoding errors and transform everything into utf-8 string
      # before logging:
      except (UnicodeEncodeError, UnicodeDecodeError):
          format_string = to_utf8(format_string)
          args = [to_utf8(p) for p in args]
          kwargs = {k: to_utf8(v) for k, v in six.iteritems(kwargs)}
          return format_string.format(*args, **kwargs)
  
      # ignore other errors
      except:
          return u''
docs: Helper: formats string with any combination of bytestrings/unicode
      strings without raising exceptions