Add logging configuration based on BasicConfig in main function

This commit is contained in:
ZiWei
2025-10-14 21:02:15 +08:00
parent 1ca1792e3c
commit 9149155232
2 changed files with 11 additions and 1 deletions

View File

@@ -180,6 +180,7 @@ def main():
working_dir = os.path.abspath(os.getcwd()) working_dir = os.path.abspath(os.getcwd())
else: else:
working_dir = os.path.abspath(os.path.join(os.getcwd(), "unilabos_data")) working_dir = os.path.abspath(os.path.join(os.getcwd(), "unilabos_data"))
if args_dict.get("working_dir"): if args_dict.get("working_dir"):
working_dir = args_dict.get("working_dir", "") working_dir = args_dict.get("working_dir", "")
if config_path and not os.path.exists(config_path): if config_path and not os.path.exists(config_path):
@@ -211,6 +212,14 @@ def main():
# 加载配置文件 # 加载配置文件
print_status(f"当前工作目录为 {working_dir}", "info") print_status(f"当前工作目录为 {working_dir}", "info")
load_config_from_file(config_path) load_config_from_file(config_path)
# 根据配置重新设置日志级别
from unilabos.utils.log import configure_logger, logger
if hasattr(BasicConfig, "log_level"):
logger.info(f"Log level set to '{BasicConfig.log_level}' from config file.")
configure_logger(loglevel=BasicConfig.log_level)
if args_dict["addr"] == "test": if args_dict["addr"] == "test":
print_status("使用测试环境地址", "info") print_status("使用测试环境地址", "info")
HTTPConfig.remote_addr = "https://uni-lab.test.bohrium.com/api/v1" HTTPConfig.remote_addr = "https://uni-lab.test.bohrium.com/api/v1"

View File

@@ -2,7 +2,7 @@ import base64
import traceback import traceback
import os import os
import importlib.util import importlib.util
from typing import Optional from typing import Optional, Literal
from unilabos.utils import logger from unilabos.utils import logger
@@ -18,6 +18,7 @@ class BasicConfig:
vis_2d_enable = False vis_2d_enable = False
enable_resource_load = True enable_resource_load = True
communication_protocol = "websocket" communication_protocol = "websocket"
log_level: Literal['TRACE', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] = "DEBUG" # 'TRACE', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'
@classmethod @classmethod
def auth_secret(cls): def auth_secret(cls):