diff --git a/xinference/deploy/cmdline.py b/xinference/deploy/cmdline.py index 64b3c565e3..b76ed8f1d9 100644 --- a/xinference/deploy/cmdline.py +++ b/xinference/deploy/cmdline.py @@ -11,8 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - - +import configparser import logging import os import sys @@ -31,6 +30,32 @@ ) +def get_config_string(log_level: str) -> str: + return f""" + [loggers] + keys=root + + [handlers] + keys=stream_handler + + [formatters] + keys=formatter + + [logger_root] + level={log_level.upper()} + handlers=stream_handler + + [handler_stream_handler] + class=StreamHandler + formatter=formatter + level={log_level.upper()} + args=(sys.stderr,) + + [formatter_formatter] + format=%(asctime)s %(name)-12s %(process)d %(levelname)-8s %(message)s + """ + + def get_endpoint(endpoint: Optional[str]) -> str: # user didn't specify the endpoint. if endpoint is None: @@ -58,9 +83,10 @@ def cli( if ctx.invoked_subcommand is None: from .local import main - if log_level: - logging.basicConfig(level=logging.getLevelName(log_level.upper())) - logging_conf = dict(level=log_level.upper()) + logging_conf = configparser.RawConfigParser() + logger_config_string = get_config_string(log_level) + logging_conf.read_string(logger_config_string) + logging.config.fileConfig(logging_conf) # type: ignore address = f"{host}:{get_next_port()}" @@ -103,9 +129,10 @@ def supervisor( def worker(log_level: str, endpoint: Optional[str], host: str): from ..deploy.worker import main - if log_level: - logging.basicConfig(level=logging.getLevelName(log_level.upper())) - logging_conf = dict(level=log_level.upper()) + logging_conf = configparser.RawConfigParser() + logger_config_string = get_config_string(log_level) + logging_conf.read_string(logger_config_string) + logging.config.fileConfig(level=logging.getLevelName(log_level.upper())) # type: ignore endpoint = get_endpoint(endpoint) diff --git a/xinference/deploy/worker.py b/xinference/deploy/worker.py index 702c8b2ee5..32d1da6eae 100644 --- a/xinference/deploy/worker.py +++ b/xinference/deploy/worker.py @@ -14,7 +14,7 @@ import asyncio import logging -from typing import Dict, Optional +from typing import Any, Dict, Optional import xoscar as xo @@ -53,7 +53,7 @@ async def _start_worker( await pool.join() -def main(address: str, supervisor_address: str, logging_conf: Optional[Dict] = None): +def main(address: str, supervisor_address: str, logging_conf: Any = None): loop = asyncio.get_event_loop() task = loop.create_task(_start_worker(address, supervisor_address, logging_conf))