LiteyukiBot-TriM/liteyuki/log.py

64 lines
1.5 KiB
Python
Raw Normal View History

2024-08-12 11:44:30 +08:00
# -*- coding: utf-8 -*-
"""
Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
@Time : 2024/7/27 上午9:12
@Author : snowykami
@Email : snowykami@outlook.com
@File : log.py
@Software: PyCharm
"""
import sys
2024-10-06 02:39:10 +08:00
2024-08-12 11:44:30 +08:00
import loguru
logger = loguru.logger
# DEBUG日志格式
debug_format: str = (
"<c>{time:YYYY-MM-DD HH:mm:ss}</c> "
"<lvl>[{level.icon}]</lvl> "
"<c><{name}.{module}.{function}:{line}></c> "
"{message}"
)
# 默认日志格式
default_format: str = (
"<c>{time:MM-DD HH:mm:ss}</c> "
"<lvl>[{level.icon}]</lvl> "
"<c><{name}></c> "
"{message}"
)
def get_format(level: str) -> str:
if level == "DEBUG":
return debug_format
else:
return default_format
def init_log(config: dict):
"""
在语言加载完成后执行
Returns:
"""
logger.remove()
logger.add(
sys.stdout,
level=0,
diagnose=False,
format=get_format(config.get("log_level", "INFO")),
)
show_icon = config.get("log_icon", True)
2024-10-06 02:39:10 +08:00
logger.level("DEBUG", color="<blue>", icon=f"{'🐛' if show_icon else ''}")
logger.level("INFO", color="<normal>", icon=f"{'' if show_icon else ''}")
logger.level("SUCCESS", color="<green>", icon=f"{'' if show_icon else ''}")
logger.level("WARNING", color="<yellow>", icon=f"{'⚠️' if show_icon else ''}")
logger.level("ERROR", color="<red>", icon=f"{'' if show_icon else ''}")
2024-08-12 11:44:30 +08:00
2024-10-06 02:39:10 +08:00
init_log(config={})