From b36ab493b3ad6fbd1d663493cd2362a247c3308f Mon Sep 17 00:00:00 2001 From: Yuhong Guo Date: Thu, 20 Mar 2025 17:10:32 +0800 Subject: [PATCH] Enable setting sglang logger from Env Variable `SGLANG_LOGGING_CONFIG_PATH ` (#4592) Signed-off-by: Yuhong Guo --- python/sglang/srt/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/sglang/srt/utils.py b/python/sglang/srt/utils.py index 6e2158c48..ddfba13f5 100644 --- a/python/sglang/srt/utils.py +++ b/python/sglang/srt/utils.py @@ -727,6 +727,16 @@ def prepare_model_and_tokenizer(model_path: str, tokenizer_path: str): def configure_logger(server_args, prefix: str = ""): + if SGLANG_LOGGING_CONFIG_PATH := os.getenv("SGLANG_LOGGING_CONFIG_PATH"): + if not os.path.exists(SGLANG_LOGGING_CONFIG_PATH): + raise Exception( + "Setting SGLANG_LOGGING_CONFIG_PATH from env with " + f"{SGLANG_LOGGING_CONFIG_PATH} but it does not exist!" + ) + with open(SGLANG_LOGGING_CONFIG_PATH, encoding="utf-8") as file: + custom_config = json.loads(file.read()) + logging.config.dictConfig(custom_config) + return format = f"[%(asctime)s{prefix}] %(message)s" # format = f"[%(asctime)s.%(msecs)03d{prefix}] %(message)s" logging.basicConfig(