logger.h

makinori comes equipped with a logger used to emit periodic server updates. User code is welcome (and encouraged) to use the same utilities for consistent logging output.

API

enum mn_log_level

The available log levels. Setting a log level using mn_log_set_level() enables logs of the given level and higher.

unsigned int MN_LOG_LEVEL_DEBUG = 0
unsigned int MN_LOG_LEVEL_INFO = 1
unsigned int MN_LOG_LEVEL_NOTICE = 2
unsigned int MN_LOG_LEVEL_WARN = 3
unsigned int MN_LOG_LEVEL_ERROR = 4
void mn_log_set_level(enum mn_log_level const)

Set the per-thread log level. The default log level is determined by the configured value.

mn_log(level, msg, ...)

Emit a log with contents msg at log level level.

mn_log_debug(msg, ...)

Emit a log with contents msg at the MN_LOG_LEVEL_DEBUG level.

mn_log_info(msg, ...)

Emit a log with contents msg at the MN_LOG_LEVEL_INFO level.

mn_log_notice(msg, ...)

Emit a log with contents msg at the MN_LOG_LEVEL_NOTICE level.

mn_log_warn(msg, ...)

Emit a log with contents msg at the MN_LOG_LEVEL_WARN level.

mn_log_error(msg, ...)

Emit a log with contents msg at the MN_LOG_LEVEL_ERROR level.

mn_trace(tag, msg, ...)

Unlike the level-specific logging functions, this emits a log without consulting the current log level. Instead, application code is expected to introduce a #define (or similar) to toggle the log. For example:

#define TRACE_REQUEST true

mn_trace(TRACE_REQUEST, "Received request with ID %d", id);

Traces are not emitted when NDEBUG is set.

mn_perror(msg, ...)

A leaner perror alternative that only outputs the status code. This is useful for two reasons:

  1. This macro’s output is consistent with other logging facilities.

  2. perror can consume a lot of stack which is potentially problematic in small coroutines.