summaryrefslogtreecommitdiff
path: root/log.c
blob: eab204c0fdbc19689fd0f256ead666a2c945481a (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
#define _POSIX_C_SOURCE 200112L

#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>

#include "log.h"

static int save;
static time_t now;
static struct tm *tm;
static char buf[25];		/* strlen("2011-10-08T07:07:09+1111") + 1 */
static va_list ap;
static enum loglevel def_loglevel = LOG_DEBUG;

void
logmsg(enum loglevel level, const char *format,...)
{
	if (def_loglevel < level) {
		return;
	}
	save = errno;

	time(&now);
	tm = localtime(&now);
	strftime(buf, sizeof buf, "%FT%T%z", tm);

	printf("%s ", buf);
	va_start(ap, format);
	vprintf(format, ap);
	va_end(ap);
	printf("\n");

	errno = save;
}