diff --git a/bot.py b/bot.py
index 287bf2d..782c870 100644
--- a/bot.py
+++ b/bot.py
@@ -20,9 +20,13 @@ env_enable_minecraft = os.environ.get("ENABLE_MINECRAFT", "none")
def main():
+ if env.upper() == 'DEBUG' or env.upper() == 'DEV':
+ console_log_level = 'DEBUG'
+ else:
+ console_log_level = 'INFO'
init_logger(LOG_PATH, [
BotExceptionMessage,
- ])
+ ], console_log_level=console_log_level)
nonebot.init()
diff --git a/konabot/common/log.py b/konabot/common/log.py
index 753dbac..96e3305 100644
--- a/konabot/common/log.py
+++ b/konabot/common/log.py
@@ -18,7 +18,7 @@ def file_exception_filter(
否则,返回 True(允许记录)。
"""
exception_info = record.get("exception")
-
+
if exception_info:
exception_type = exception_info[0]
@@ -29,8 +29,9 @@ def file_exception_filter(
def init_logger(
- log_dir: Path,
- ignored_exceptions: List[Type[Exception]]
+ log_dir: Path,
+ ignored_exceptions: List[Type[Exception]],
+ console_log_level: str = "INFO",
) -> None:
"""
配置全局 Loguru Logger。
@@ -47,7 +48,7 @@ def init_logger(
logger.add(
sys.stderr,
- level="INFO",
+ level=console_log_level,
colorize=True,
format="{time:HH:mm:ss} | {level: <8} | {name}:{function}:{line} - {message}",
)
@@ -76,4 +77,4 @@ def init_logger(
)
logger.info("Loguru Logger 初始化完成!")
- logger.info(f"控制台日志级别: INFO")
+ logger.info(f"控制台日志级别: {console_log_level}")
diff --git a/konabot/plugins/simple_notify/__init__.py b/konabot/plugins/simple_notify/__init__.py
index 7ceeb86..6e85894 100644
--- a/konabot/plugins/simple_notify/__init__.py
+++ b/konabot/plugins/simple_notify/__init__.py
@@ -1,10 +1,8 @@
import asyncio as asynkio
import datetime
-import functools
from pathlib import Path
from typing import Any, Literal, cast
-import signal
import nonebot
import ptimeparse
from loguru import logger
@@ -123,7 +121,9 @@ def create_notify_task(notify: Notify, fail2remove: bool = True):
try:
await asynkio.sleep((notify.notify_time - begin_time).total_seconds())
except asynkio.CancelledError:
- logger.debug("代办提醒被信号中止,任务退出")
+ logger.debug(
+ f"代办提醒被信号中止,任务退出 NOTIFY={notify.notify_msg} TIME={notify.notify_time}"
+ )
return
else:
logger.warning(
@@ -254,19 +254,3 @@ async def _():
save_notify_config(cfg)
DATA_FILE_LOCK.release()
- loop = asynkio.get_running_loop()
-
- # 解决 asynk task 没有被 cancel 的问题
- async def shutdown(sig: signal.Signals):
- logger.info(f"收到 {sig.name} 指令,正在关闭所有的东西")
- for task in ASYNK_TASKS:
- task.cancel()
- await asynkio.gather(*ASYNK_TASKS, return_exceptions=True)
- logger.info("所有的代办提醒 Task 都已经退出了")
-
- for sig in (signal.SIGINT, signal.SIGTERM):
- loop.add_signal_handler(
- sig, functools.partial(asynkio.create_task, shutdown(sig))
- )
-
- await asynkio.gather(*ASYNK_TASKS)