def log(self, msg, level="info"):
        """
        log this information to syslog or user provided logfile.
        """
        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, f"{msg}")
        else:
            # Binary mode so fs encoding setting is not an issue
            with self.config["log_file"].open("ab") as f:
                log_time = time.strftime("%Y-%m-%d %H:%M:%S")
                # nice formatting 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 = "\n" + msg
                out = f"{log_time} {level.upper()} {msg}\n"
                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)

        log this information to syslog or user provided logfile.
        
py3status/core.py