Skip to content

Backend Callback

Eduard Mishkurov edited this page Jun 3, 2026 · 1 revision

Callback Backend

CallbackBackend is a built-in backend that forwards accepted log records to an application-provided function.

Use it when the application already owns the final delivery path: a UI console, test collector, telemetry bridge, in-process diagnostics panel, or another custom sink where deriving a full backend class would be unnecessary.

Type id

The backend type id is:

CallbackBackend

It can be created by the backend factory and can appear in configuration/control paths, but JSON cannot configure the actual callback function pointer.

Callback signature

The callback type is defined in CallbackBackend.h:

typedef void (*CallbackBackendProc)(
  Context& context
  , const ChannelPtr& owner
  , void* userData
);

The callback receives:

  • context — the current log record context
  • owner — the channel that owns the backend
  • userData — an opaque pointer supplied by application code

Installing the callback

Application code installs the callback with SetCallback():

backend->SetCallback(MyCallback, myUserData);

The backend also provides:

  • GetCallback()
  • GetUserData()

If the callback pointer is nullptr, Display() returns without writing anything.

Configuration

CallbackBackendConfig only parses common backend fields from BackendConfig.

A JSON configuration can create a CallbackBackend object:

{
  "type": "CallbackBackend"
}

but it cannot serialize or restore a process-local C/C++ function pointer or userData. Those must be installed by code after the backend object exists.

Threading and lifetime notes

CallbackBackend calls the callback synchronously from the backend display path. If the callback performs slow work, it should queue that work itself and return quickly.

If the callback formats the record through Context::Apply() or reads formatted buffers from the context, copy the data before returning if it needs to survive beyond the callback call. The context is a per-record object, not persistent storage.

When not to use it

Do not use CallbackBackend as a replacement for FileBackend or ConsoleBackend when the built-in backend already matches the destination. It is mainly an integration point for application-owned delivery code.

Clone this wiki locally