C Collections

clogger · Section 3

clog_derive

clog_derive - create a derived logger sharing the same output target

C Collections (libccollections, -lccollections)

#include <ccollections/clogger.h>
 
clog clog_derive(clog parent);

Creates a new derived logger that writes to the same file descriptor as
parent and shares its log-rotation state and its write lock, so the
writes of parent and of every derived logger are serialised by that one
lock and land in the same destination.
 
The derived logger starts with a snapshot of the structured fields and
the minimum log level that parent has at the moment of the call.  After
that the two loggers keep fully independent field maps and levels, and
adding, removing or changing a field or the level on one of them has no
effect on the other.
 
When the original logger writes to a file with log rotation configured,
the rotation belongs to the shared output target.  A write through any
handle, the root or a derived one, rotates the file once a limit is
reached, and rotation goes on as long as any handle is open, even after
the root logger is closed.
 
Release a derived logger with clog_close() once you do not need it.
The shared backing store is refcounted, so the file stays open until
every handle, the root and every derived logger, is closed.

parent  Source logger to derive from.

A new derived logger handle on success, or CLOG_NULL when a memory
allocation fails.

A derived logger takes the output format and the syslog facility from
the shared backing store.  If parent logs asynchronously, the derived
logger does too, through the same writer thread, and it allocates
through the allocator of the root logger.  A change to the output format
or the syslog facility through any handle is visible at once to every
handle that writes to the same fd.
Thread-safe.  The snapshot of the fields is synchronised with a
concurrent clog_set_field(3), clog_remove_field(3) or
clog_clear_fields(3) call on parent, whatever write a sibling logger
has in progress.
Asserts when parent is CLOG_NULL, stale or already closed.

clog_create_from_fd_mp(3), clog_create_from_file_path_mp(3), clog_close(3)