xtc_log(3)

---

xtc_log(3)

async ring-buffer logger

XTC_LOG(3) Library Functions Manual XTC_LOG(3)

xtc_log_create, xtc_log_destroy, xtc_log_write, xtc_log_vwrite, xtc_log_drain, xtc_log_set_floor, xtc_log_set_default, xtc_log_default, xtc_log_drop_count, XTC_LOG_DEBUG_F, XTC_LOG_INFO_F, XTC_LOG_WARN_F, XTC_LOG_ERROR_Fasync ring-buffer logger

#include <xtc.h>
#include <xtc_log.h>

int
xtc_log_create(const xtc_log_opts_t *opts, xtc_log_t **out);

void
xtc_log_destroy(xtc_log_t *log);

int
xtc_log_write(xtc_log_t *log, xtc_log_level_t level, const char *fmt, ...);

void
xtc_log_vwrite(xtc_log_t *log, xtc_log_level_t lvl, const char *fmt, va_list ap);

int
xtc_log_drain(xtc_log_t *log);

int
xtc_log_set_floor(xtc_log_t *log, xtc_log_level_t lvl);

int
xtc_log_set_default(xtc_log_t *log);

xtc_log_t *
xtc_log_default(void);

int
xtc_log_drop_count(const xtc_log_t *log);

xtc_log is a predictable-latency logger: callers append records to an in-memory ring buffer; a sink consumer drains the ring on a timer or explicit flush. Producers never block; if the ring is full, the oldest record is dropped silently.

Levels: XTC_LOG_DEBUG, XTC_LOG_INFO, XTC_LOG_WARN, XTC_LOG_ERROR. A configurable global level filter elides cheaper records before formatting.

(opts.sink_fd) or opts.sink_fn: records are written to either a file descriptor (stdout, syslog fd, etc.) or a user callback.

The () macros are convenience wrappers that look up a process-default xtc_log_t and call () with the right level.

() forces an immediate flush; called from the metrics proc on a timer or at process exit.

() is the va_list variant of () for callers that already hold a ap. () sets a per-logger minimum level below which records are dropped before formatting. () installs log as the process-wide default the XTC_LOG_*_F() macros route through, and () returns the current default. () reports how many records were dropped because the ring was full.

xtc_log_t *log;
xtc_log_opts_t opts = XTC_LOG_OPTS_DEFAULT;
opts.sink_fd = STDOUT_FILENO;
opts.min_level = XTC_LOG_INFO;

xtc_log_create(&opts, &log);
XTC_LOG_INFO_F("server started on port %d", port);

xtc_cfg(3), xtc_stats(3), xtc(7)

Appeared in xtc 0.1.

May 28, 2026 Debian

View the mdoc source