KUTIL_LOG(3)

NAME
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_warnx - format log messages

LIBRARY
libkcgi

SYNOPSIS
#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, ...);

DESCRIPTION
These functions format messages for reporting on stderr, avoiding common CGI script pitfalls such as unwittingly using localtime(3) when in a chroot(2). Moreover, they allow for a consist logging output format, as most web servers are inconsistent on how they log script output. See kutil_openlog(3) for configuring an alternative log file.

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.

The kutil_err(), kutil_errx(), kutil_verr(), and kutil_verrx() functions exit with EXIT_FAILURE. They will never return.

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

The kutil_err(), kutil_verr(), kutil_log(), kutil_vlog(), kutil_vwarn(), and kutil_warn() 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" and "level", if NULL, will be rendered as "-". The date is formatted as an HTTP date (RFC 822) in GMT.

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

BUGS
The log message size is limited to 1023 bytes. Anything over that will be silently truncated.