diff --git a/liteyuki/utils/__init__.py b/liteyuki/utils/__init__.py
index a6db964..879cccb 100644
--- a/liteyuki/utils/__init__.py
+++ b/liteyuki/utils/__init__.py
@@ -20,7 +20,8 @@ def init():
nonebot.logger.error("This project requires Python3.10+ to run, please upgrade your Python Environment.")
exit(1)
- print("\033[34m" + r""" __ ______ ________ ________ __ __ __ __ __ __ ______
+ print("\033[34m" + r"""
+ __ ______ ________ ________ __ __ __ __ __ __ ______
/ | / |/ |/ |/ \ / |/ | / |/ | / |/ |
$$ | $$$$$$/ $$$$$$$$/ $$$$$$$$/ $$ \ /$$/ $$ | $$ |$$ | /$$/ $$$$$$/
$$ | $$ | $$ | $$ |__ $$ \/$$/ $$ | $$ |$$ |/$$/ $$ |
@@ -28,7 +29,8 @@ $$ | $$ | $$ | $$ | $$ $$/ $$ | $$ |$$ $$< $$ |
$$ | $$ | $$ | $$$$$/ $$$$/ $$ | $$ |$$$$$ \ $$ |
$$ |_____ _$$ |_ $$ | $$ |_____ $$ | $$ \__$$ |$$ |$$ \ _$$ |_
$$ |/ $$ | $$ | $$ | $$ | $$ $$/ $$ | $$ |/ $$ |
-$$$$$$$$/ $$$$$$/ $$/ $$$$$$$$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ """ + "\033[0m")
+$$$$$$$$/ $$$$$$/ $$/ $$$$$$$$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/
+""" + "\033[0m")
nonebot.logger.info(
f"Run Liteyuki with Python{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro} "
f"at {sys.executable}"
diff --git a/liteyuki/utils/data.py b/liteyuki/utils/data.py
index 4ae3d2f..b764afc 100644
--- a/liteyuki/utils/data.py
+++ b/liteyuki/utils/data.py
@@ -116,6 +116,7 @@ class Database(BaseORMAdapter):
Returns:
"""
+ nonebot.logger.warning("Database.auto_migrate is deprecated, use Database.migrate instead")
table_name = ''
for model in args:
model: type(LiteModel)
diff --git a/liteyuki/utils/log.py b/liteyuki/utils/log.py
index 3144506..78fed63 100644
--- a/liteyuki/utils/log.py
+++ b/liteyuki/utils/log.py
@@ -1,33 +1,14 @@
import sys
-import logging
-from typing import TYPE_CHECKING
-from .language import get_default_lang
import loguru
+from typing import TYPE_CHECKING
+from .config import config, load_from_yaml
+logger = loguru.logger
if TYPE_CHECKING:
+ # avoid sphinx autodoc resolve annotation failed
+ # because loguru module do not have `Logger` class actually
from loguru import Logger, Record
-logger: "Logger" = loguru.logger
-
-
-class LoguruHandler(logging.Handler): # pragma: no cover
- """logging 与 loguru 之间的桥梁,将 logging 的日志转发到 loguru。"""
-
- def emit(self, record: logging.LogRecord):
- try:
- level = logger.level(record.levelname).name
- except ValueError:
- level = record.levelno
-
- frame, depth = sys._getframe(6), 6
- while frame and frame.f_code.co_filename == logging.__file__:
- frame = frame.f_back
- depth += 1
-
- logger.opt(depth=depth, exception=record.exc_info).log(
- level, record.getMessage()
- )
-
def default_filter(record: "Record"):
"""默认的日志过滤器,根据 `config.log_level` 配置改变日志等级。"""
@@ -36,13 +17,31 @@ def default_filter(record: "Record"):
return record["level"].no >= levelno
-default_format: str = (
+# DEBUG日志格式
+debug_format: str = (
"{time:YYYY-MM-DD} {time:HH:mm:ss} "
"[{level.icon}] "
+ "<{name}.{module}.{function}:{line}> "
+ "{message}"
+)
+
+# 默认日志格式
+default_format: str = (
+ "{time:MM-DD} {time:HH:mm:ss} "
+ "[{level.icon}] "
"<{name}> "
"{message}"
)
-"""默认日志格式"""
+
+
+def get_format(level: str) -> str:
+ if level == "DEBUG":
+ return debug_format
+ else:
+ return default_format
+
+
+logger = loguru.logger.bind(get_format=get_format)
logger.remove()
logger_id = logger.add(
@@ -50,17 +49,12 @@ logger_id = logger.add(
level=0,
diagnose=False,
filter=default_filter,
- format=default_format,
+ format=get_format(load_from_yaml('config.yml').get("log_level", "INFO")),
)
-slang = get_default_lang()
-logger.level("DEBUG", color="", icon=f"*️⃣ DDDEBUG")
-logger.level("INFO", color="", icon=f"ℹ️ IIIINFO")
-logger.level("SUCCESS", color="", icon=f"✅ SUCCESS")
-logger.level("WARNING", color="", icon=f"⚠️ WARNING")
-logger.level("ERROR", color="", icon=f"⭕ EEERROR")
-"""默认日志处理器 id"""
-__autodoc__ = {
- "logger_id": False
-}
+logger.level("DEBUG", color="", icon=f"*️⃣==DEBUG")
+logger.level("INFO", color="", icon=f"ℹ️===INFO")
+logger.level("SUCCESS", color="", icon=f"✅SUCCESS")
+logger.level("WARNING", color="", icon=f"⚠️WARNING")
+logger.level("ERROR", color="", icon=f"⭕==ERROR")