Created
January 10, 2022 18:29
-
-
Save lisp3r/7d018d3e00dc31b9e6649ca850f87109 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
class OwOFormatter(logging.Formatter): | |
def __init__(self): | |
super().__init__(fmt="%(levelno)d: %(msg)s", datefmt=None, style='%') | |
self.info_fmt = "[^w^] %(msg)s" | |
self.err_fmt = "[UwU] %(msg)s" | |
self.warn_fmt = "[OwO] %(msg)s" | |
self.dbg_fmt = "[-_-] %(msg)s" | |
def format(self, record): | |
format_orig = self._style._fmt | |
if record.levelno == logging.DEBUG: | |
self._style._fmt = self.dbg_fmt | |
elif record.levelno == logging.INFO: | |
self._style._fmt = self.info_fmt | |
elif record.levelno == logging.ERROR: | |
self._style._fmt = self.err_fmt | |
elif record.levelno == logging.WARN: | |
self._style._fmt = self.warn_fmt | |
result = logging.Formatter.format(self, record) | |
self._style._fmt = format_orig | |
return result | |
hdlr = logging.StreamHandler() | |
hdlr.setFormatter(OwOFormatter()) | |
log = logging.getLogger(__name__) | |
log.addHandler(hdlr) | |
log.setLevel(logging.DEBUG) | |
log.info('Information') | |
log.debug('Debug message') | |
log.warning('Warning message') | |
log.error('Error message') | |
# [^w^] Information | |
# [-_-] Debug message | |
# [OwO] Warning message | |
# [UwU] Error message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment