-
Notifications
You must be signed in to change notification settings - Fork 3
Backend Callback
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.
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.
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
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.
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.
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.
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.
logme — flexible runtime logging system
Home · Getting Started · Architecture · Output · Backends · Configuration
GitHub: https://github.com/efmsoft/logme
- Home
- Getting Started
- Why logme?
- Core Concepts
- Logging Macros
- Fatal Handling
- Crash Logging
- glog Compatibility
- C API
- Choosing Logging Macros
- Function tracing
- Trace Points
- Override Scopes
- Advanced Features
- Collapse Logging
- Feature Map
- Overview
- Console Backend
- Debugger Backend
- File Backend
- File Rotation & Retention
- Buffer Backend
- Ring Buffer Backend
- SharedFile Backend
- Callback Backend
- Windows Event Log Backend
- Custom Backends
- Runtime Control
- Configuration
- Configuration JSON
- Control Server
- Environment Control
- Control Policies
- Trace Points
- Message Filtering