summaryrefslogtreecommitdiff
path: root/log.c
blob: 603db7f89c39f71e9dc995601cc67410be2aebeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdarg.h>
#include <stdbool.h>

#include "log.h"

static bool use_syslog;

void log_lvl(int lvl, const char *fmt, ...)
{
	va_list ap;

	va_start(ap, fmt);

	if (!use_syslog) {
		FILE *out = stderr;
		switch (lvl) {
		case LOG_ERR:
			fputs("Error: ", stderr);
			break;
		case LOG_WARNING:
			fputs("Warning: ", stderr);
			break;
		case LOG_INFO:
		case LOG_DEBUG:
			out = stdout;
			break;
		}
		vfprintf(out, fmt, ap);
	} else {
		vsyslog(lvl, fmt, ap);
	}

	va_end(ap);
}

void log_to_syslog(void)
{
	use_syslog = true;
}