Skip to content

Commit

Permalink
[Serve] fix missing message body for json log formats (#42729) (#42874)
Browse files Browse the repository at this point in the history
Pick of #42729

Signed-off-by: Gene Su <e870252314@gmail.com>
  • Loading branch information
GeneDer committed Jan 31, 2024
1 parent 0784b9d commit fce7a36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions python/ray/serve/_private/logging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ def format(self, record: logging.LogRecord) -> str:
SERVE_LOG_APPLICATION
]

if SERVE_LOG_MESSAGE in record.__dict__:
record_format[SERVE_LOG_MESSAGE] = (
SERVE_LOG_RECORD_FORMAT[SERVE_LOG_MESSAGE] % record.__dict__
)
message_formatter = logging.Formatter(
SERVE_LOG_RECORD_FORMAT[SERVE_LOG_MESSAGE]
)
record_format[SERVE_LOG_MESSAGE] = message_formatter.format(record)

if SERVE_LOG_EXTRA_FIELDS in record.__dict__:
if not isinstance(record.__dict__[SERVE_LOG_EXTRA_FIELDS], dict):
Expand Down
6 changes: 6 additions & 0 deletions python/ray/serve/tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,12 @@ def format_and_verify_json_output(record, expected_record: dict):
expected_json["deployment"] = "component"
expected_json["replica"] = "component_id"

# Ensure message exists in the output.
# Note that there is no "message" key in the record dict until it has been
# formatted. This check should go before other fields are set and checked.
expected_json["message"] = "my_path:1 - my_message"
format_and_verify_json_output(record, expected_json)

# Set request id
record.request_id = "request_id"
expected_json["request_id"] = "request_id"
Expand Down

0 comments on commit fce7a36

Please sign in to comment.