chttpclient · Section 3
chttpcli_set_engine_logger
NAME
chttpcli_set_engine_logger - set the logger for the diagnostics of the async engine of chttpclient
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/chttpclient.h> ccol_retval chttpcli_set_engine_logger(clog cl);
DESCRIPTION
This function derives a child logger from cl with the extra field component=http-client-engine, and installs it as the diagnostics logger of the shared async engine behind Tier 2 and Tier 3. If an engine logger was installed before, it is closed. You can call this function at any time, and it takes effect at once. The engine keeps the child logger across every stop and restart until another call to this function replaces it. chttpcli_do_async, chttpcli_do_async_streaming and the pooled-sync wrappers built on them (chttpcli_do_pooled and chttpcli_do_pooled_streaming) share one ceventloop reactor. That reactor serves the whole process and every chttpcli instance in it, the default client included, and the library starts it the first time it is needed. This function captures that reactor's diagnostics, such as a failed TLS handshake or a connect error. It is separate from the logger of each client, and from the reactor of chttpsvr_set_engine_logger as well: chttpserver and chttpclient each own a fully independent static reactor, and one process can run both at the same time. While no logger from this function is installed, the library opens a fallback logger every time the engine starts and closes it when the engine stops. The fallback writes to fd 2 at level CLOG_FATAL, and this engine never logs its own diagnostics above CLOG_INFO, so the fallback stays silent until you install a more talkative logger with this function. The caller keeps ownership of cl and may close it once this call returns, because the child logger shares cl's destination and clogger keeps that destination open while any logger that shares it is open. The engine owns the child logger, and the caller must not close it. The library closes it when another call replaces it, and at process exit or library unload if no engine is running at that point. For a logger from clog_create_from_fd or clog_create_from_fd_mp, that destination is the logger's state and not the file descriptor: Such a logger never owns its fd, and no clog_close closes it; see clog_create_from_fd(3). The engine keeps writing to that fd after you close cl, so the fd itself must stay open until another call to this function replaces or releases the engine logger, or until the process exits. Calling it with cl equal to CLOG_NULL releases the installed engine logger. The engine closes its child logger, and every later start of the engine uses the fallback logger again. While the engine runs, the release is refused with ccol_not_permitted because the engine logs through that logger, so destroy every client and call chttpcli_engine_wait first. Once a release has returned ccol_success, the engine makes no further call through that logger, and its destination, its file descriptor and cl's allocator may go away.
RETURN VALUE
ccol_success, if the call succeeds.
ccol_not_enough_memory, if the library cannot allocate the child
logger.
ccol_not_permitted, if cl is CLOG_NULL and the engine runs.
ccol_invalid_args, if cl is not CLOG_NULL but is closed or stale;
nothing changes, and the engine keeps the logger that it had.
SEE ALSO
chttpcli_engine_wait(3), chttpcli_set_engine_mem_mgmt_procs(3), clog_create_from_fd(3), chttpcli_do_async(3), chttpcli_do_pooled(3), chttpsvr_set_engine_logger(3)