Reference

log_log(3)

provides unified logging

NAME

log_log, log_vlog, log_open, log_close, log_unit_init, log_unit_free, log_set_mask, log_get_mask, log_mask2str, log_set_mask_str – provides unified logging

SYNOPSIS

#include <parse_units.h>

#include <log.h>

void log_log(Log_unit *unit, unsigned level, const char *fmt, ...);

void log_vlog(Log_unit *unit, unsigned level, const char *fmt, va_list args);

Log_method *log_open(char *progname, char *fname);

void log_close(Log_method *method);

Log_unit *log_unit_init(Log_method *method, const char *name, struct units *lognames, unsigned long default_mask);

void log_unit_free(Log_method *method, Log_unit *unit);

void log_set_mask(Log_unit *unit, unsigned long mask);

unsigned log_get_mask(Log_unit *unit);

void log_mask2str(Log_method *method, Log_unit *unit, char *buf, size_t sz);

void log_set_mask_str(Log_method *method, Log_unit *default_unit, const char *str);

DESCRIPTION

log_log will let you have a unified logging system throu-out your whole project. No more strange errnos like EINVAL returned from libraries since they can print to stderr (not knowing what fd will be connected to fd number 2).

log_open() will open a Log_method that all Log_units will log though, Log_method controls to what device the log is sent. Logging devices, passed in fname, are syslog, /dev/stderr, or a file.

Options can be passes to the subsystem with an extra colon. Valid options are:

syslog[:pid,no-delay,console,stderr[:facility]]

{/dev/stderr,/file}[:notime]

log_close() closeses the Log_method and assosiated Log_units.

log_unit_init() will return a logging unit, that is used by a subsystem.

log_unit_free() will free a logging unit allocated by log_unit_init().

log_set_mask() set the logging mask for a logging unit.

log_get_mask() get the logging mask for a logging unit.

log_mask2str() convert the longing mask for `unit' (or all if this is NULL), to a string that can be printed. The string can be parsed by log_set_mask_str().

log_set_mask_str() will set the mask for `default_unit' (or all if this is NULL).

EXAMPLE

#include <parse_units.h>
#include <log.h>
#include <err.h>
enum { A_WARNING = 1, A_DEBUG = 2 };
struct units u_units[] = {
    { "debug",		A_DEBUG },
    { "warning", 	A_WARNING },
    { NULL, 		0 }
};
int
main (int argc, char **argv)
{
    Log_method *m;
    Log_unit *u;
    char buf[1024];
    m = log_open ("log-tester", "/dev/stderr");
    if (m == NULL)
	errx (1, "log_open");
    u = log_unit_init (m, "test-foo", u_units, A_WARNING);
    if (u == NULL)
	errx (1, "log_unit_init");
    log_log (u, A_WARNING, "this should show");
    log_log (u, A_DEBUG, "this should NOT show");
    log_mask2str (m, NULL, buf, sizeof(buf));
    printf ("logmask: %s\n", buf);
    log_close (m);
    return 0;
}

BUGS

Should maybe include a log_logx version.

SEE ALSO

syslog(3), syslogd(8)