Skip to content

Add log callback support to Logger class#149

Open
nbarbier-amira wants to merge 1 commit intotriton-inference-server:mainfrom
nbarbier-amira:feature/log-callback
Open

Add log callback support to Logger class#149
nbarbier-amira wants to merge 1 commit intotriton-inference-server:mainfrom
nbarbier-amira:feature/log-callback

Conversation

@nbarbier-amira
Copy link
Copy Markdown

Adds callback-based logging to the Logger class, which allows applications embedding Triton to hook into the logging system and forward messages to their own logging infrastructure.

Motivation

Currently the only way to capture Triton logs programmatically is to redirect to a file and parse it. This is awkward for applications that want to integrate Triton logs with their existing logging setup (structured logging, log aggregation services, etc). See triton-inference-server/server#8304.

Changes

  • New LogCallbackFn typedef and SetLogCallback() method on Logger
  • Callback receives level, filename, line, and message
  • Option to replace default logging or run callback alongside it
  • LOG_SET_CALLBACK macro follows existing pattern

Example

void my_logger(Logger::Level level, const char* file, int line, 
               const char* msg, void* ctx) {
    // forward to spdlog, log4cxx, etc
}

gLogger_.SetLogCallback(my_logger, nullptr, true);  // replace default

Notes

This is the foundation for adding TRITONSERVER_ServerOptionsSetLogCallback to the C API in triton-core (separate PR).

Backward compatible - default behavior unchanged when no callback is registered.

This adds the ability to register a callback function that receives log
messages, enabling integration with external logging systems.

Features:
- New LogCallbackFn typedef for the callback function signature
- SetLogCallback() method to register/unregister callbacks
- Callbacks receive log level, source filename, line number, and message
- Option to replace default logging or use callback in addition to it
- LOG_SET_CALLBACK macro for convenient access

The callback is invoked from the Log() method before (or instead of)
writing to stdout/stderr/file, depending on the replace_default_logger
setting.

Resolves triton-inference-server/server#8304
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.

2 participants