KUTIL_LOG(3) Library Functions Manual KUTIL_LOG(3)

kutil_err, kutil_errx, kutil_info, kutil_log, kutil_logx, kutil_verr, kutil_verrx, kutil_vinfo, kutil_vlog, kutil_vlogx, kutil_vwarn, kutil_vwarnx, kutil_warn, kutil_warnxformat log messages

library “libkcgi”

#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>

void
kutil_err(const struct kreq *r, const char *ident, const char *fmt, ...);

void
kutil_errx(const struct kreq *r, const char *ident, const char *fmt, ...);

void
kutil_info(const struct kreq *r, const char *ident, const char *fmt, ...);

void
kutil_log(const struct kreq *r, const char *level, const char *ident, const char *fmt, ...);

void
kutil_logx(const struct kreq *r, const char *level, const char *ident, const char *fmt, ...);

void
kutil_verr(const struct kreq *r, const char *ident, const char *fmt, va_list ap);

void
kutil_verrx(const struct kreq *r, const char *ident, const char *fmt, va_list ap);

void
kutil_vinfo(const struct kreq *r, const char *ident, const char *fmt, va_list ap);

void
kutil_vlog(const struct kreq *r, const char *level, const char *ident, const char *fmt, va_list ap);

void
kutil_vlogx(const struct kreq *r, const char *level, const char *ident, const char *fmt, va_list ap);

void
kutil_vwarn(const struct kreq *r, const char *ident, const char *fmt, va_list ap);

void
kutil_vwarnx(const struct kreq *r, const char *ident, const char *fmt, va_list ap);

void
kutil_warn(const struct kreq *r, const char *ident, const char *fmt, ...);

void
kutil_warnx(const struct kreq *r, const char *ident, const char *fmt, ...);

These functions consistently format and output messages on standard error. See kutil_openlog(3) for configuring an alternative log destination.

These functions accept the following variables:

const struct kreq *r
Active request handle opened with khttp_parse(3). If NULL, the remote host field will be omitted.
const char *level
A human-readable log level. If NULL, no level is printed. For functions not accepting this argument, the INFO, WARN, and ERROR values are used for the informational, warning, and error functions, respectively.
const char *ident
The client identity of the caller. This adheres to the common CGI practise of connecting a message to a logged-in user. If NULL, no ident is printed.
const char *fmt
The printf(3) style format string for the variable argument or argument list following. This formats the log message. If NULL, no message is printed.

The (), (), kutil_verr(), and () functions exit with EXIT_FAILURE. They never return.

The log messages are filtered on output: non-printable (see isprint(3)) characters are replaced with “?” and space characters (\a, \b, \f, \n, \r, \t, \v, \0) are shown as literal escape characters.

The (), (), (), (), (), and () functions print out the current errno following the log message.

The output format is as follows, with a trailing newline:

addr ident [date] level msg
addr ident [date] level msg: errmsg

Here, "addr" is the remote host as passed to the CGI script or "-" if r is NULL; and where "ident" "level" and "msg", if NULL, will be rendered as "-". The date is formatted as an HTTP date (RFC 822) in GMT.

These functions were written by Kristaps Dzonsons <kristaps@bsd.lv>.

December 2, 2023 OpenBSD 7.4