Skip to content

Custom Backends

Eduard Mishkurov edited this page Jan 23, 2026 · 2 revisions

Custom Backends

logme allows users to implement custom backends.

Overview

A custom backend can be used to:

  • Capture log output for testing
  • Forward logs to external systems
  • Implement application-specific storage

Integration

Custom backends:

  • Implement the backend interface
  • Can be attached to any channel
  • Participate in normal routing

Example

A reference implementation of a custom backend is provided in the test suite (TestBackend).

This backend is used to validate routing, filtering, and message delivery behavior in automated tests.

Implementing a Custom Backend

To implement your own backend, create a class derived from Logme::Backend and implement at minimum the following method:

virtual void Display(Context& context, const char* line) = 0;

Inside Display, to obtain a fully prepared log line (with formatting, timestamps, prefixes, etc.), call Context::Apply:

int nc;
const char* buffer = context.Apply(Owner, Owner->GetFlags(), line, nc);

The returned buffer is always null-terminated. The nc value contains the length of the buffer (equivalent to strlen(buffer)).

The resulting string can then be written to a file, sent over the network, stored in memory, or otherwise processed according to the backend’s purpose.

Clone this wiki locally