Skip to content

Instantly share code, notes, and snippets.

@duckythescientist
Last active July 17, 2024 17:40
Show Gist options
  • Save duckythescientist/a3ea6a084a68280f94c373ac20cdfd4e to your computer and use it in GitHub Desktop.
Save duckythescientist/a3ea6a084a68280f94c373ac20cdfd4e to your computer and use it in GitHub Desktop.
Is your Python logging not UwU enough for you? Well, do I have a solution!
#!/usr/bin/env python3
"""
Notices your logging, OwO what's this?
"""
import logging
def configure_ducklogging():
rootlog = logging.getLogger()
log_format = "%(asctime)s | %(name)s %(levelname)s %(module)s:%(funcName)s:%(lineno)d [%(process)d] | %(message)s"
log_dateformat = "%Y-%m-%dT%H:%M:%S" # ISO 8601
import os
try:
import coloredlogs
if os.name == "nt":
# Windows need colorama initialized to properly use coloredlogs
import colorama
colorama.init(convert=True)
except ImportError:
logging.basicConfig(
level=logging.DEBUG, format=log_format, datefmt=log_dateformat
)
else:
coloredlogs.install(
level=logging.DEBUG,
datefmt=log_dateformat,
field_styles={
"asctime": {"color": "green"},
"levelname": {"color": "blue", "bold": True},
"module": {"color": "yellow"},
"process": {"color": "magenta"},
},
fmt=log_format,
)
# rootlog.setLevel(logging.DEBUG)
rootlog.setLevel(0)
# I think Parso is being loud because of my iPython
noisy_log = logging.getLogger("parso")
noisy_log.setLevel(logging.WARNING)
noisy_log = logging.getLogger("matplotlib")
noisy_log.setLevel(logging.WARNING)
noisy_log = logging.getLogger("asyncio")
noisy_log.setLevel(logging.WARNING)
def uwu(shortlevelnames=False):
import os
import re
import logging
# https://stackoverflow.com/a/24894475
def replace_keep_case(word, replacement, text):
def func(match):
g = match.group()
if g.islower():
return replacement.lower()
if g.istitle():
return replacement.title()
if g.isupper():
return replacement.upper()
return replacement
return re.sub(word, func, text, flags=re.I)
def owo_filter(record):
pairs = (
("small", "smol"),
("cute", "kawaii"),
("fluff", "floof"),
("love", "luv"),
("stupid", "baka"),
("what", "nani"),
("meow", "nya"),
("your", "ur"),
("you're", "ur"),
("fuck", "fwickk"),
("hell", "hekk"),
("my", "mwy"),
("to", "tuwu"),
("had", "hawd"),
("you", "yuw"),
("go", "gow"),
("and", "awnd"),
("have", "haw"),
("debug", "debuwug"),
("info", "infowo"),
)
text = record.msg
for a, b in pairs:
text = replace_keep_case(a, b, text)
text = re.sub(r"l[el](s?)\b", r"w\1", text)
text = re.sub(r"[LR]", "W", text)
text = re.sub(r"[lr]", "w", text)
text = re.sub(r"([MmNn])([Oo])", r"\1y\2", text)
record.msg = text
return True
rootlog = logging.getLogger()
if shortlevelnames:
logging.addLevelName(logging.CRITICAL, "ΘOΘ")
logging.addLevelName(logging.ERROR, "X.X")
logging.addLevelName(logging.WARNING, "ÒwÓ")
logging.addLevelName(logging.INFO, "o.O")
logging.addLevelName(logging.DEBUG, "UwU")
else:
logging.addLevelName(logging.CRITICAL, "ΘOΘ CWITICAL")
logging.addLevelName(logging.ERROR, "X.X EWWOR")
logging.addLevelName(logging.WARNING, "ÒwÓ WAWNING")
logging.addLevelName(logging.INFO, "o.O INFOwO")
logging.addLevelName(logging.DEBUG, "UwU DEBUwUG")
for handler in rootlog.handlers:
handler.addFilter(owo_filter)
if __name__ == "__main__":
# print(text)
configure_ducklogging()
uwu()
logger = logging.getLogger(__name__)
# logging_tree.printout()
logger.debug("This text is debug")
logger.info("This text is info")
logger.warning("This text is a warning")
logger.error("Something went really wrong")
logger.critical("Catastrophic failure, quitting")
logger.info("Sparkle sparkles sparkling")
logger.warning("Ths program is the most important piece of software that I have ever written")
@duckythescientist
Copy link
Author

duckythescientist commented Jan 10, 2023

2024-07-17T13:38:38 | __main__ UwU DEBUwUG uwu_logging:<module>:137 [150034] | This text is debuwug
2024-07-17T13:38:38 | __main__ o.O INFOwO uwu_logging:<module>:138 [150034] | This text is infowo
2024-07-17T13:38:38 | __main__ ÒwÓ WAWNING uwu_logging:<module>:139 [150034] | This text is a wawning
2024-07-17T13:38:38 | __main__ X.X EWWOR uwu_logging:<module>:140 [150034] | Something went weawwy wwong
2024-07-17T13:38:38 | __main__ ΘOΘ CWITICAL uwu_logging:<module>:141 [150034] | Catastwophic faiwuwe, quitting

2024-07-17T13:38:38 | __main__ o.O INFOwO uwu_logging:<module>:143 [150034] | Spawkw spawkws spawkwing
2024-07-17T13:38:38 | __main__ ÒwÓ WAWNING uwu_logging:<module>:144 [150034] | Ths pwogwam is the myost impowtant piece of softwawe that I haw evew wwitten

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment