C Collections

chttpserver · Section 3

chttpsvr_set_engine_logger

chttpsvr_set_engine_logger - set the logger for engine-level diagnostics

C Collections (libccollections, -lccollections)

#include <ccollections/chttpserver.h>
 
ccol_retval chttpsvr_set_engine_logger(clog cl);

When cl is not CLOG_NULL, the function derives a child logger from
cl, adds the field component=http-server-engine to it and installs it
as the diagnostics logger of the shared reactor.  It closes the
logger that an earlier call derived and, if a running engine has one,
the fallback logger of that engine.
 
The reactor logs to this handle in exactly three places: A failed TLS
handshake, a failed bind of the listen socket, and each pass of the
idle-timeout sweep that closes one or more connections.  If no logger
from this function is in place when the engine starts, the engine
installs a fallback logger of its own.  That logger writes to fd 2 at
level CLOG_FATAL, like the internal stderr-only, FATAL-only logger of
chttpsvr_create.  All three diagnostics above log below CLOG_FATAL,
so the min_level of the fallback logger filters every one of them out
and in practice it writes nothing.  Install a more useful logger with
this function.
 
You can call it at any time: Before the first chttpsvr_start, while
the reactor runs, and after a full engine stop.  The child logger
serves the reactor that is running now, if there is one, and every
reactor that a later chttpsvr_start brings up after a full engine
stop, until another call of this function replaces it.
 
The derived child logger belongs to the library.  It is closed when
another call replaces it, when a call with CLOG_NULL releases it,
or at process exit or library unload; if an engine is still running
at that point, the engine closes it when it stops.  The caller must
not close it.  cl stays the caller's, and the caller may close it at
any time, because the child logger is a handle of its own and keeps
the destination of cl open for as long as it lives.
 
A call with CLOG_NULL releases the engine logger.  The child
logger is closed at once, and the next engine that starts uses the
fallback logger.  While an engine runs, the release is refused with
ccol_not_permitted, because the engine logs through that logger, so
make the call after chttpsvr_engine_wait() has returned.  A release
with no logger installed does nothing and succeeds.

ccol_success on success, including a release when no logger is
                  installed.
ccol_not_permitted when cl is CLOG_NULL and an engine runs.
ccol_invalid_args when cl is not CLOG_NULL but is closed or
                  stale; nothing changes, and the engine keeps the
                  logger that it had.
ccol_not_enough_memory when the child logger cannot be
                  allocated.

The child logger allocates and frees through the allocator of cl.
An application that destroys that allocator before the process exits
must release the engine logger with CLOG_NULL first.  Otherwise
the library closes the child logger at process exit through an
allocator that is gone.
 
When cl writes to a file descriptor that the application opened, as
a logger from clog_create_from_fd does, the descriptor stays the
application's, and the child logger writes to it until it is closed.
Keep the descriptor open while the engine logger is installed, and
release the engine logger before you close the descriptor.

chttpsvr_start(3), chttpsvr_engine_stop(3), chttpsvr_engine_wait(3)