feat: Support a log callback in the common Logger - #158
Conversation
whoisj
left a comment
There was a problem hiding this comment.
Looks good. I have a couple of requests.
whoisj
left a comment
There was a problem hiding this comment.
Approved. I don't think the atomic is needed, but it's also just fine.
|
Fix copyrights |
Greptile SummaryThis PR adds an optional structured log callback to the shared
Confidence Score: 3/5Not safe to merge as-is — the timestamp computation in the callback path references POSIX-only timeval fields that do not exist when building on Windows, producing a compile error for any Windows consumer. The callback dispatch logic is sound on Linux/macOS, but the new timestamp_us conversion in ~LogMessage() uses timestamp_.tv_sec and timestamp_.tv_usec unconditionally. On Windows timestamp_ is SYSTEMTIME with no such fields; the existing LogTimestamp() handles this correctly via #ifdef _WIN32 guards that the new code omits. The test is also silently excluded from non-JSON builds. src/logging.cc — the callback path needs platform guards around the timestamp conversion. src/test/CMakeLists.txt — the logging test subdirectory should be moved outside the TRITON_COMMON_ENABLE_JSON conditional. Important Files Changed
Sequence DiagramsequenceDiagram
participant Producer as Logging Thread
participant LM as LogMessage (dtor)
participant GL as gLogger_
participant CB as LogCallbackFn
participant Sink as Default Sink (stdout/stderr/file)
Producer->>LM: ~LogMessage()
LM->>GL: LogCallback()
alt callback is set
GL-->>LM: "const LogCallbackFn& callback"
LM->>LM: compute timestamp_us (POSIX only)
LM->>LM: build raw_message (heading + message)
LM->>CB: callback(level, is_verbose, file, line, timestamp_us, message)
CB-->>LM: return (exceptions swallowed)
LM-->>Producer: return (default sink skipped)
else no callback
LM->>LM: LogPreamble() + escape message
LM->>GL: Log(log_record, level)
GL->>Sink: write to file / cout / cerr
Sink-->>GL:
GL-->>LM:
LM-->>Producer: return
end
Reviews (1): Last reviewed commit: "Merge branch 'main' of https://github.co..." | Re-trigger Greptile |
Adds an optional callback to the shared
Loggerso an embedding application can receive each log record as structured fields (level, file, line, timestamp, message) instead of parsing Triton's stdout/stderr text. When a callback is set, records go to it and the default sink is skipped. When it is not set, behavior is unchanged.CI: triton-inference-server/server#8858