From 86cf3f7b2d0a7e7fc8185f58b48ed246d7ed4abb Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Wed, 11 Dec 2024 06:17:51 -0500 Subject: [PATCH] [Python] Add flag to disable logging config (#3060) Fixes #2780 This adds a environment variable `MLC_UNSET_LOGGING` to force the logging format to be disabled. It also removes `enable_logging` calls except for in MLC entrypoints (e.g. CLI main). --- python/mlc_llm/bench/api_endpoint.py | 1 - python/mlc_llm/bench/request_processor.py | 1 - python/mlc_llm/bench/request_record.py | 1 - python/mlc_llm/cli/delivery.py | 1 - python/mlc_llm/cli/lib_delivery.py | 1 - python/mlc_llm/cli/model_metadata.py | 1 - python/mlc_llm/serve/engine.py | 1 - python/mlc_llm/serve/engine_base.py | 1 - python/mlc_llm/serve/sync_engine.py | 1 - python/mlc_llm/support/logging.py | 3 +++ 10 files changed, 3 insertions(+), 9 deletions(-) diff --git a/python/mlc_llm/bench/api_endpoint.py b/python/mlc_llm/bench/api_endpoint.py index a44b6da690..0fe1a2391e 100644 --- a/python/mlc_llm/bench/api_endpoint.py +++ b/python/mlc_llm/bench/api_endpoint.py @@ -12,7 +12,6 @@ from mlc_llm.bench.request_record import Metrics, RequestRecord, ServerMetrics from mlc_llm.support import logging -logging.enable_logging() logger = logging.getLogger(__name__) diff --git a/python/mlc_llm/bench/request_processor.py b/python/mlc_llm/bench/request_processor.py index dd9c9f6150..fbe876de24 100644 --- a/python/mlc_llm/bench/request_processor.py +++ b/python/mlc_llm/bench/request_processor.py @@ -19,7 +19,6 @@ from mlc_llm.protocol.openai_api_protocol import ChatCompletionMessage, DebugConfig from mlc_llm.support import logging -logging.enable_logging() logger = logging.getLogger(__name__) diff --git a/python/mlc_llm/bench/request_record.py b/python/mlc_llm/bench/request_record.py index c4992615b2..99cc1b3c1a 100644 --- a/python/mlc_llm/bench/request_record.py +++ b/python/mlc_llm/bench/request_record.py @@ -8,7 +8,6 @@ from mlc_llm.protocol.openai_api_protocol import ChatCompletionRequest from mlc_llm.support import logging -logging.enable_logging() logger = logging.getLogger(__name__) diff --git a/python/mlc_llm/cli/delivery.py b/python/mlc_llm/cli/delivery.py index a1279e21a7..ed1cfeaa13 100644 --- a/python/mlc_llm/cli/delivery.py +++ b/python/mlc_llm/cli/delivery.py @@ -16,7 +16,6 @@ from mlc_llm.support.argparse import ArgumentParser from mlc_llm.support.style import bold, green, red -logging.enable_logging() logger = logging.getLogger(__name__) GEN_CONFIG_OPTIONAL_ARGS = [ diff --git a/python/mlc_llm/cli/lib_delivery.py b/python/mlc_llm/cli/lib_delivery.py index a5d678fbe2..960386eaaa 100644 --- a/python/mlc_llm/cli/lib_delivery.py +++ b/python/mlc_llm/cli/lib_delivery.py @@ -16,7 +16,6 @@ from mlc_llm.support.constants import MLC_TEMP_DIR from mlc_llm.support.style import bold, green, red -logging.enable_logging() logger = logging.getLogger(__name__) diff --git a/python/mlc_llm/cli/model_metadata.py b/python/mlc_llm/cli/model_metadata.py index 80f63ff34f..c83c39f36e 100644 --- a/python/mlc_llm/cli/model_metadata.py +++ b/python/mlc_llm/cli/model_metadata.py @@ -13,7 +13,6 @@ from mlc_llm.support.config import ConfigBase from mlc_llm.support.style import green, red -logging.enable_logging() logger = logging.getLogger(__name__) diff --git a/python/mlc_llm/serve/engine.py b/python/mlc_llm/serve/engine.py index a0f3b8d197..1ddfd059f9 100644 --- a/python/mlc_llm/serve/engine.py +++ b/python/mlc_llm/serve/engine.py @@ -30,7 +30,6 @@ from . import engine_base -logging.enable_logging() logger = logging.getLogger(__name__) diff --git a/python/mlc_llm/serve/engine_base.py b/python/mlc_llm/serve/engine_base.py index d038dd0282..9cf4f59db0 100644 --- a/python/mlc_llm/serve/engine_base.py +++ b/python/mlc_llm/serve/engine_base.py @@ -28,7 +28,6 @@ from mlc_llm.support.style import green from mlc_llm.tokenizers import TextStreamer, Tokenizer -logging.enable_logging() logger = logging.getLogger(__name__) diff --git a/python/mlc_llm/serve/sync_engine.py b/python/mlc_llm/serve/sync_engine.py index 6c2c7b701a..72b8c2f2ef 100644 --- a/python/mlc_llm/serve/sync_engine.py +++ b/python/mlc_llm/serve/sync_engine.py @@ -29,7 +29,6 @@ from mlc_llm.support import logging from mlc_llm.tokenizers import TextStreamer, Tokenizer -logging.enable_logging() logger = logging.getLogger(__name__) diff --git a/python/mlc_llm/support/logging.py b/python/mlc_llm/support/logging.py index 023d1240f1..41097905bb 100644 --- a/python/mlc_llm/support/logging.py +++ b/python/mlc_llm/support/logging.py @@ -4,10 +4,13 @@ """ import logging +import os def enable_logging(): """Enable MLC's default logging format""" + if os.getenv("MLC_UNSET_LOGGING"): + return logging.basicConfig( level=logging.INFO, style="{",