[Serve] fix missing message body for json log formats - #42729
Conversation
Signed-off-by: Gene Su <e870252314@gmail.com>
|
@GeneDer so with these changes, what would be the difference in the example screenshot you posted? Would there just be empty |
Yes, the screenshot shows the differences. The first highlighted part is without this change. You see those "Finished recovering deployments...", "Starting proxy with name..." missing. The second run on the bottom shows the fix revealed the missing logs :) |
| SERVE_LOG_APPLICATION | ||
| ] | ||
|
|
||
| if SERVE_LOG_MESSAGE in record.__dict__: |
There was a problem hiding this comment.
@edoakes Basically this if statement is blocking the message from populating since the formatter is not yet called and the "message" field doesn't exist on the log record yet
|
@edoakes @sihanwang41 Just in case the notification is missed. Would be nice to get this in 🙏 |
Why are these changes needed?
Found quite a lot of logs misses log message body when working on the logs observability (on Workspaces).

After a bit more digging, it seems like in some occasion, the
messageattribute would not be presented on therecord.__dict__so caused the if statement to be skipped and logged a line without themessagebody. Internally inLogRecord, themessagefield is "...computed asmsg % args. This is set when Formatter.format() is invoked." This PR useslogging.Formatterto format the message directly instead of relying on Python's string substitution so the message can always be computed. Also did it in the TDD way to ensure there is a test covering it.LogRecord Doc: https://docs.python.org/3/library/logging.html#logrecord-objects
Related issue number
Checks
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/under thecorresponding
.rstfile.