summaryrefslogtreecommitdiff
path: root/dots_manager/kawaii_logger.py
blob: f82da23f0c9ad9712f316c7f181aea91131746e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import logging
import sys
import random

MOOD_EMOTICONS = {
    "debug": ["(=^・^=)", "(=・ェ・=)", "(=^-ω-^=)", "(=^‥^=)"],
    "info": ["(^• ω •^)", "(=^・ω・^)y=", "(≚ᄌ≚)", "(。♥‿♥。)"],
    "warning": ["(; ̄Д ̄)", "(¬_¬;)", "(・ัω・ั)", "(・_・ヾ"],
    "error": ["(╥﹏╥)", "(≧Д≦)", "(;′⌒`)", "(T▽T)"],
}

MOOD_SUFFIXES = {
    "_happy": ["(ノ◕ヮ◕)ノ*:・゚✧", "(๑˃ᴗ˂)ﻭ", "(^▽^)", "( ˘⌣˘)♡(˘⌣˘ )"],
    "_sad": ["(。•́︿•̀。)", "(╯︵╰,)", "(ಥ﹏ಥ)", "(︶︹︺)"],
    "_anxious": ["(ノдヽ)", "(◎_◎;)", "(・_・;)", "(゚Д゚;)"],
}

LEVEL_COLORS = {
    logging.DEBUG: "\033[95m",  # light magenta
    logging.INFO: "\033[96m",  # light cyan
    logging.WARNING: "\033[93m",  # light yellow
    logging.ERROR: "\033[91m",  # light red
    logging.CRITICAL: "\033[35m",  # magenta
}

RESET_COLOR = "\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 "(・ω・)"

        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}"


def setup_logger(verbose: bool = False) -> logging.Logger:
    """sets up a super cute logger with sparkles and cat faces ✨"""
    logger = logging.getLogger("dotfiles")
    logger.setLevel(logging.DEBUG if verbose else logging.INFO)

    handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(KawaiiFormatter())

    logger.handlers.clear()
    logger.addHandler(handler)
    logger.propagate = False

    return logger