diff options
author | Hunt <lizhunt@amazon.com> | 2025-06-03 11:58:25 -0700 |
---|---|---|
committer | Hunt <lizhunt@amazon.com> | 2025-06-03 11:58:25 -0700 |
commit | ee9ad10b5cc9850c3e2ed1946f70e0cef429fb48 (patch) | |
tree | b6b0411b02127951cc28292425a35a1830c2758d /dots_manager/kawaii_logger.py | |
parent | 64d060d2730cd212b2932879036eb33f7336ef38 (diff) | |
download | dotfiles-ee9ad10b5cc9850c3e2ed1946f70e0cef429fb48.tar.gz dotfiles-ee9ad10b5cc9850c3e2ed1946f70e0cef429fb48.zip |
Refactor
Diffstat (limited to 'dots_manager/kawaii_logger.py')
-rw-r--r-- | dots_manager/kawaii_logger.py | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/dots_manager/kawaii_logger.py b/dots_manager/kawaii_logger.py index f82da23..f13ea14 100644 --- a/dots_manager/kawaii_logger.py +++ b/dots_manager/kawaii_logger.py @@ -2,20 +2,22 @@ import logging import sys import random -MOOD_EMOTICONS = { - "debug": ["(=^・^=)", "(=・ェ・=)", "(=^-ω-^=)", "(=^‥^=)"], - "info": ["(^• ω •^)", "(=^・ω・^)y=", "(≚ᄌ≚)", "(。♥‿♥。)"], - "warning": ["(; ̄Д ̄)", "(¬_¬;)", "(・ัω・ั)", "(・_・ヾ"], - "error": ["(╥﹏╥)", "(≧Д≦)", "(;′⌒`)", "(T▽T)"], +MOOD_KAOMOJI = { + "<_mood.happy>": ["(ノ◕ヮ◕)ノ*:・゚✧", "(^▽^)", "( ˘⌣˘)♡(˘⌣˘ )"], + "<_mood.excited>": ["(๑˃ᴗ˂)ﻭ"], + "<_mood.sad>": ["(。•́︿•̀。)", "(╯︵╰,)", "(ಥ﹏ಥ)", "(︶︹︺)"], + "<_mood.anxious>": ["(ノдヽ)", "(◎_◎;)", "(・_・;)", "(゚Д゚;)"], } -MOOD_SUFFIXES = { - "_happy": ["(ノ◕ヮ◕)ノ*:・゚✧", "(๑˃ᴗ˂)ﻭ", "(^▽^)", "( ˘⌣˘)♡(˘⌣˘ )"], - "_sad": ["(。•́︿•̀。)", "(╯︵╰,)", "(ಥ﹏ಥ)", "(︶︹︺)"], - "_anxious": ["(ノдヽ)", "(◎_◎;)", "(・_・;)", "(゚Д゚;)"], +LEVEL_KAOMOJI = { + logging.DEBUG: ["(=^・^=)", "(=・ェ・=)", "(=^-ω-^=)", "(=^‥^=)"], + logging.INFO: ["(^• ω •^)", "(=^・ω・^)y=", "(≚ᄌ≚)", "(。♥‿♥。)"], + logging.WARNING: ["(; ̄Д ̄)", "(¬_¬;)", "(・ัω・ั)", "(・_・ヾ"], + logging.ERROR: ["(╥﹏╥)", "(≧Д≦)", "(;′⌒`)", "(T▽T)"], + logging.CRITICAL: ["(╯°□°)╯︵ ┻━┻"], } -LEVEL_COLORS = { +LEVEL_ANSI_STYLES = { logging.DEBUG: "\033[95m", # light magenta logging.INFO: "\033[96m", # light cyan logging.WARNING: "\033[93m", # light yellow @@ -23,32 +25,33 @@ LEVEL_COLORS = { logging.CRITICAL: "\033[35m", # magenta } -RESET_COLOR = "\033[0m" +RESET_ANSI = "\033[0m" class KawaiiFormatter(logging.Formatter): - def format(self, record): - level = record.levelname.lower() - color = LEVEL_COLORS.get(record.levelno, "") - base_emotes = MOOD_EMOTICONS.get(level, []) - mood_emotes = [] - - emote_pool = mood_emotes if mood_emotes else base_emotes - emote = random.choice(emote_pool) if emote_pool else "(・ω・)" - + def format(self, record: logging.LogRecord): message = record.msg.strip() ts = self.formatTime(record, "%Y-%m-%d %H:%M:%S") lvl = record.levelname filename = record.filename lineno = str(record.lineno) - formatted = f"[{ts}] {color}[{lvl} {filename}:{lineno}]{RESET_COLOR} {color}{message}{RESET_COLOR} {emote}" - return f"{formatted}{RESET_COLOR}" + split_last_word = message.rsplit(" ", 1) + last_word = split_last_word[-1] if split_last_word else "" + emote_pool = LEVEL_KAOMOJI.get(record.levelno, []) + if last_word in MOOD_KAOMOJI: + message = split_last_word[0] if len(split_last_word) > 1 else "" + emote_pool = MOOD_KAOMOJI.get(last_word, []) + emote = random.choice(emote_pool) if emote_pool else "(・ω・)" + + color = LEVEL_ANSI_STYLES.get(record.levelno, "") + + formatted = f"[{ts}] {color}[{lvl} {filename}:{lineno}]{RESET_ANSI} {color}{message}{RESET_ANSI} {emote}" + return f"{formatted}{RESET_ANSI}" -def setup_logger(verbose: bool = False) -> logging.Logger: - """sets up a super cute logger with sparkles and cat faces ✨""" - logger = logging.getLogger("dotfiles") +def setup_logger(verbose: bool = False, logger_name: str = "") -> logging.Logger: + logger = logging.getLogger(logger_name) logger.setLevel(logging.DEBUG if verbose else logging.INFO) handler = logging.StreamHandler(sys.stdout) |