Merge branch 'release-1.0'
[reservoir_sample] / notify.c
diff --git a/notify.c b/notify.c
new file mode 100644 (file)
index 0000000..78e7e44
--- /dev/null
+++ b/notify.c
@@ -0,0 +1,36 @@
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "notify.h"
+
+/* common messaging hook */
+
+/* generic notifier */
+static
+void notify_default_(unsigned int l, const char *fmt, ...) {
+       FILE *f = stderr;
+       va_list ap;
+       const char *level_names[] = {
+               "FATAL",
+               "ERROR",
+               "INFO",
+               "VERBOSE",
+               "DEBUG",
+               "DEBUG_LOCK",
+       };
+       const size_t levels = sizeof level_names / sizeof *level_names;
+
+       va_start(ap, fmt);
+       flockfile(f);
+       if (l < levels) {
+               fprintf(f, "%s", level_names[l]);
+       } else {
+               fprintf(f, "[%d] ", l);
+       }
+       vfprintf(f, fmt, ap);
+       funlockfile(f);
+       va_end(ap);
+}
+
+notify_fn_t *notify __attribute__((format(printf, 2, 3))) = notify_default_;