Skip to content

Logging

Lee Yunjin edited this page Oct 7, 2026 · 1 revision

Logging

CWIST has three logging facilities:

Facility Header Output Use
Access log middleware <cwist/sys/app/middleware.h> stdout, one line per request request logs (common, combined, JSON)
Application logger <cwist/sys/app/logger.h> stderr your own named loggers with levels and colors
Internal log macros <cwist/core/log.h> stderr framework diagnostics

Access logs

cwist_app_use(app, cwist_mw_access_log(CWIST_LOG_JSON));
{"time":"2026-10-07T10:52:34.123Z","client":"127.0.0.1","rid":"jx6ilguz4yrgd101","method":"GET","path":"/x","protocol":"HTTP/1.1","status":200,"duration_ms":0,"req_bytes":0,"res_bytes":2}

CWIST_LOG_COMMON and CWIST_LOG_COMBINED print Apache-style lines; combined adds Referer and User-Agent. The request id comes from cwist_mw_request_id() when it runs earlier in the chain. Requests that match no route are not logged (middleware does not run on route misses; see Middleware).

Application logger

#include <cwist/sys/app/logger.h>

cwist_logger *log = cwist_logger_create("billing");
cwist_logger_set_level(log, CWIST_LOG_INFO);
cwist_logger_set_colors(log, true);
cwist_logger_info(log, "charged %d cents", 1299);
cwist_logger_destroy(log);
Function Description
cwist_logger *cwist_logger_create(const char *name) / void cwist_logger_destroy(cwist_logger *log) Named logger.
void cwist_logger_set_level(log, level) Minimum level: CWIST_LOG_DEBUG, _INFO, _WARN, _ERROR.
void cwist_logger_set_colors(log, bool) ANSI colors.
cwist_logger_log(log, level, fmt, ...), _debug, _info, _warn, _error printf-style output.

Internal log macros

CWIST_LOG_INFO(fmt, ...), CWIST_LOG_WARN, CWIST_LOG_ERROR and CWIST_LOG_DEBUG write [LEVEL] [YYYY-MM-DD HH:MM:SS] message to stderr when the global g_cwist_log_level allows it. The default is CWIST_LOG_LEVEL_NONE, so the framework's internal logs are silent until you set the variable:

#include <cwist/core/log.h>
g_cwist_log_level = CWIST_LOG_LEVEL_INFO;   /* INFO, WARN and ERROR */

The level test happens before the arguments are evaluated, so disabled log calls cost almost nothing. cwist_log_init() is declared in the header but not implemented; set g_cwist_log_level directly.

Separate environment switches enable specific diagnostics: CWIST_ASYNC_DEBUG (reactor and async-path failures) and CWIST_H3_DEBUG (lsquic logs); see Configuration and Environment.

Clone this wiki locally