From 8baef077204065bcd50a9bc4a8ac6b632976c0a8 Mon Sep 17 00:00:00 2001 From: AL76 <735756072@qq.com> Date: Sun, 9 Mar 2025 22:22:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=85=A8=E5=B1=80log?= =?UTF-8?q?ger=E5=88=9D=E5=A7=8B=E5=8C=96=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bot.py b/bot.py index 4a463f5db..fbe300a6b 100644 --- a/bot.py +++ b/bot.py @@ -12,6 +12,7 @@ import platform # 获取没有加载env时的环境变量 env_mask = {key: os.getenv(key) for key in os.environ} + def easter_egg(): # 彩蛋 from colorama import init, Fore @@ -91,6 +92,17 @@ def load_env(): RuntimeError(f"ENVIRONMENT 配置错误,请检查 .env 文件中的 ENVIRONMENT 变量及对应 .env.{env} 是否存在") +def load_logger(): + logger.remove() # 移除默认配置 + logger.add( + sys.stderr, + format="{time:YYYY-MM-DD HH:mm:ss.SSS} | {level: <7} | {name:.<8}:{function:.<8}:{line: >4} - {message}", + colorize=True, + level=os.getenv("LOG_LEVEL", "INFO") # 根据环境设置日志级别,默认为INFO + ) + def scan_provider(env_config: dict): provider = {} @@ -136,6 +148,7 @@ if __name__ == "__main__": init_config() init_env() load_env() + load_logger() env_config = {key: os.getenv(key) for key in os.environ} scan_provider(env_config)