Skip to content

Commit

Permalink
Remove redundant dquote escaping in json logger format
Browse files Browse the repository at this point in the history
  • Loading branch information
vtaskow committed Jul 21, 2023
1 parent 2a01680 commit 7ac1275
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions mlserver/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ class ModelLoggerFormatter(logging.Formatter):
"""Log formatter incorporating model details, e.g. name and version."""

_UNSTRUCTURED_FORMAT = "%(asctime)s [%(name)s]%(model)s %(levelname)s - %(message)s"
_STRUCTURED_FORMAT = "{\"time\":\"%(asctime)s\", \"name\": \"%(name)s\", " \
"\"level\": \"%(levelname)s\", \"message\": \"%(message)s\"" \
" %(model)s}"
_STRUCTURED_FORMAT = (
'{"time": "%(asctime)s", "name": "%(name)s", "level": "%(levelname)s", '
'"message": "%(message)s" %(model)s}'
)

def __init__(self, use_structured_logging: bool):
super().__init__(
Expand All @@ -64,9 +65,9 @@ def _format_unstructured_model_details(name: str, version: str) -> str:
def _format_structured_model_details(name: str, version: str) -> str:
if not name:
return ""
model_details = f", \"model_name\": \"{name}\""
model_details = f', "model_name": "{name}"'
if version:
model_details += f", \"model_version\": \"{version}\""
model_details += f', "model_version": "{version}"'
return model_details

def format(self, record: logging.LogRecord) -> str:
Expand Down

0 comments on commit 7ac1275

Please sign in to comment.