summaryrefslogtreecommitdiff
path: root/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'log.c')
-rw-r--r--log.c36
1 files changed, 36 insertions, 0 deletions
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 <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;
+}