Merge branch 'release/1.3'
[reservoir_sample] / notify.c
1 #include <stdlib.h>
2 #include <stdarg.h>
3 #include <stdio.h>
4
5 #include "notify.h"
6
7 /* common messaging hook */
8
9 /* generic notifier */
10 static
11 void notify_default_(unsigned int l, const char *fmt, ...) {
12 FILE *f = stderr;
13 va_list ap;
14 const char *level_names[] = {
15 "FATAL",
16 "ERROR",
17 "INFO",
18 "VERBOSE",
19 "DEBUG",
20 "DEBUG_LOCK",
21 };
22 const size_t levels = sizeof level_names / sizeof *level_names;
23
24 va_start(ap, fmt);
25 flockfile(f);
26 if (l < levels) {
27 fprintf(f, "%s", level_names[l]);
28 } else {
29 fprintf(f, "[%d] ", l);
30 }
31 vfprintf(f, fmt, ap);
32 funlockfile(f);
33 va_end(ap);
34 }
35
36 notify_fn_t *notify __attribute__((format(printf, 2, 3))) = notify_default_;