Skip to content

feat: Support a log callback in the common Logger - #158

Merged
pskiran1 merged 14 commits into
mainfrom
spolisetty/tri-1194-integrate-triton-logging-into-dynamo
Jul 23, 2026
Merged

feat: Support a log callback in the common Logger#158
pskiran1 merged 14 commits into
mainfrom
spolisetty/tri-1194-integrate-triton-logging-into-dynamo

Conversation

@pskiran1

@pskiran1 pskiran1 commented Jun 25, 2026

Copy link
Copy Markdown
Member

Adds an optional callback to the shared Logger so 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

@pskiran1 pskiran1 changed the title feat: support a log callback in the common Logger feat: Support a log callback in the common Logger Jun 25, 2026

@whoisj whoisj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I have a couple of requests.

Comment thread include/triton/common/logging.h Outdated
Comment thread include/triton/common/logging.h Outdated
Comment thread src/logging.cc Outdated
@pskiran1
pskiran1 requested a review from whoisj July 4, 2026 13:58
whoisj
whoisj previously approved these changes Jul 8, 2026

@whoisj whoisj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. I don't think the atomic is needed, but it's also just fine.

Comment thread include/triton/common/logging.h Outdated
Comment thread include/triton/common/logging.h
Comment thread src/test/CMakeLists.txt
whoisj
whoisj previously approved these changes Jul 10, 2026
@pskiran1
pskiran1 requested a review from yinggeh July 13, 2026 15:55
Comment thread src/test/logging/logging_test.cc
@pskiran1
pskiran1 requested a review from yinggeh July 14, 2026 05:02
@yinggeh

yinggeh commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Fix copyrights

Comment thread include/triton/common/logging.h Outdated
@pskiran1
pskiran1 requested a review from yinggeh July 21, 2026 10:07
Comment thread include/triton/common/logging.h Outdated
Comment thread include/triton/common/logging.h Outdated
@pskiran1
pskiran1 requested a review from yinggeh July 21, 2026 14:23
pskiran1 added 2 commits July 22, 2026 14:40
 into spolisetty/tri-1194-integrate-triton-logging-into-dynamo
 into spolisetty/tri-1194-integrate-triton-logging-into-dynamo
@greptile-apps

greptile-apps Bot commented Jul 23, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds an optional structured log callback to the shared Logger singleton, allowing an embedding application to receive log records as discrete fields (level, verbose flag, file, line, timestamp in microseconds, raw message) instead of parsing formatted text from stdout/stderr. When a callback is registered it fully replaces the default sink; when absent, behavior is unchanged. A new GTest suite validates field delivery, sink exclusivity, and exception safety.

  • Core dispatch (src/logging.cc): The LogMessage destructor checks for a registered callback before falling through to the existing preamble-format-write path; the callback is invoked outside the logger mutex with exceptions silently swallowed.
  • Header API (include/triton/common/logging.h): Adds LogCallbackFn typedef, SetLogCallback/LogCallback accessors, a SetVerbose() builder on LogMessage, and patches verbose macros to chain .SetVerbose().
  • Test build (src/test/CMakeLists.txt): Wires the new logging subdirectory, but inside the TRITON_COMMON_ENABLE_JSON guard, which has no bearing on the logging test's actual dependencies.

Confidence Score: 3/5

Not 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

Filename Overview
include/triton/common/logging.h Adds LogCallbackFn typedef, SetLogCallback/LogCallback accessors, callback_ member, and SetVerbose() on LogMessage; also patches LOG_VERBOSE_FL, LOG_TABLE_VERBOSE, and LOG_PROTOBUF_VERBOSE macros to chain .SetVerbose(). The documented non-thread-safe contract is clear; level-filtering behaviour with the callback is undocumented.
src/logging.cc Implements the callback dispatch in LogMessage::~LogMessage(), including timestamp-to-microseconds conversion and exception swallowing. The timestamp_us computation references timestamp_.tv_sec/tv_usec which do not exist on Windows where timestamp_ is SYSTEMTIME; this will fail to compile on Windows builds.
src/test/CMakeLists.txt Wires the new logging test subdirectory inside the if (TRITON_COMMON_ENABLE_JSON) guard, which incorrectly suppresses the test when JSON support is disabled even though the test has no JSON dependency.
src/test/logging/CMakeLists.txt New CMake target for the logging test; correctly links triton-common-logging and GTest. No issues beyond being placed behind the wrong guard in the parent CMakeLists.
src/test/logging/logging_test.cc Three well-structured GTest cases covering structured field delivery, mutual exclusivity with the default sink, and exception safety. TearDown properly clears the global callback between tests.

Sequence Diagram

sequenceDiagram
    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
Loading

Reviews (1): Last reviewed commit: "Merge branch 'main' of https://github.co..." | Re-trigger Greptile

Comment thread src/logging.cc
Comment thread src/test/CMakeLists.txt
Comment thread include/triton/common/logging.h
@pskiran1
pskiran1 merged commit 83adf7c into main Jul 23, 2026
2 checks passed
@pskiran1
pskiran1 deleted the spolisetty/tri-1194-integrate-triton-logging-into-dynamo branch July 23, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants