code: def log(self, msg, level="info"):
          
          if not self.config.get("log_file"):
              # If level was given as a str then convert to actual level
              level = LOG_LEVELS.get(level, level)
              syslog(level, u"{}".format(msg))
          else:
              # Binary mode so fs encoding setting is not an issue
              with open(self.config["log_file"], "ab") as f:
                  log_time = time.strftime("%Y-%m-%d %H:%M:%S")
                  # nice formating of data structures using pretty print
                  if isinstance(msg, (dict, list, set, tuple)):
                      msg = pformat(msg)
                      # if multiline then start the data output on a fresh line
                      # to aid readability.
                      if "\n" in msg:
                          msg = u"\n" + msg
                  out = u"{} {} {}\n".format(log_time, level.upper(), msg)
                  try:
                      # Encode unicode strings to bytes
                      f.write(out.encode("utf-8"))
                  except (AttributeError, UnicodeDecodeError):
                      # Write any byte strings straight to log
                      f.write(out)
docs: log this information to syslog or user provided logfile.