Skip to content

Commit

Permalink
BUG: Fix log level on subprocess (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
RayJi01 authored Aug 9, 2023
1 parent 57270f7 commit 4d2f61c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
43 changes: 35 additions & 8 deletions xinference/deploy/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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()}"

Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions xinference/deploy/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import asyncio
import logging
from typing import Dict, Optional
from typing import Any, Dict, Optional

import xoscar as xo

Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit 4d2f61c

Please sign in to comment.