From e985bfa6b8facac58da9a20c3c840498e2517bb5 Mon Sep 17 00:00:00 2001 From: nirav Date: Sun, 15 Sep 2019 09:26:41 +0000 Subject: Initial commit --- log.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 log.c (limited to 'log.c') diff --git a/log.c b/log.c new file mode 100644 index 0000000..c543238 --- /dev/null +++ b/log.c @@ -0,0 +1,36 @@ +#define _POSIX_C_SOURCE 200112L + +#include +#include +#include +#include + +#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; +} -- cgit v1.2.3