Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uvicorn logging settings #531

Merged
merged 5 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mlserver/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys

from logging import Formatter, StreamHandler
import logging.config

from .settings import Settings

Expand All @@ -15,6 +16,10 @@ def get_logger():
return logger


def apply_logging_file(logging_settings: str):
logging.config.fileConfig(fname=logging_settings, disable_existing_loggers=False)


def configure_logger(settings: Settings = None):
logger = get_logger()

Expand All @@ -30,4 +35,7 @@ def configure_logger(settings: Settings = None):
if settings and settings.debug:
logger.setLevel(logging.DEBUG)

if settings and settings.logging_settings:
apply_logging_file(settings.logging_settings)

return logger
5 changes: 4 additions & 1 deletion mlserver/rest/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ async def delete_custom_handlers(self, model: MLModel):

async def start(self):
cfg = uvicorn.Config(
self._app, host=self._settings.host, port=self._settings.http_port
self._app,
host=self._settings.host,
port=self._settings.http_port,
log_config=self._settings.logging_settings,
)
self._server = _NoSignalServer(cfg)
await self._server.serve()
Expand Down
4 changes: 4 additions & 0 deletions mlserver/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class Config:
`None` to disable it
"""

# Logging settings
logging_settings: Optional[str] = None
"""Path to logging config file"""


class ModelParameters(BaseSettings):
"""
Expand Down