diff options
Diffstat (limited to 'log.c')
-rw-r--r-- | log.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -0,0 +1,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]; /* "2011-10-08T07:07:09+1111" */ +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; +} |