aboutsummaryrefslogtreecommitdiff
path: root/include/log.h
blob: c4a24305b8b4822b065e7706303f0d96072871f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef REVELA_LOG_H
#define REVELA_LOG_H

#include <errno.h>
#include <string.h>

enum log_level {
	LOG_SILENT,
	LOG_FATAL,
	LOG_ERROR,
	LOG_INFO,
	LOG_DETAIL,
	LOG_DEBUG,
};

#ifdef DEBUG
static const char *log_level_names[] = {
	"",
	"FATAL",
	"ERROR",
	"INFO",
	"DETAIL",
	"DEBUG",
};
#endif

void log_set_verbosity(enum log_level);

void log_printf(enum log_level, const char *restrict fmt, ...);

#ifdef DEBUG
#define log_print(v, fmt, ...)                           \
	log_printf(v, "[%s] %s:%d " fmt, log_level_names[v], \
	           __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_print(v, fmt, ...) \
	log_printf(v, fmt, ##__VA_ARGS__)
#endif

#ifdef DEBUG
#define log_printl(v, fmt, ...)                               \
	log_printf(v, "[%s] %s:%d " fmt "\n", log_level_names[v], \
	           __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define log_printl(v, fmt, ...) \
	log_printf(v, fmt "\n", ##__VA_ARGS__)
#endif

#ifdef DEBUG
#define log_printl_errno(v, fmt, ...)                             \
	log_printf(v, "[%s] %s:%d " fmt ": %s\n", log_level_names[v], \
	           __FILE__, __LINE__, ##__VA_ARGS__, strerror(errno))
#else
#define log_printl_errno(v, fmt, ...) \
	log_printf(v, fmt ": %s\n", ##__VA_ARGS__, strerror(errno))
#endif

#endif