-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclog.h
46 lines (37 loc) · 789 Bytes
/
clog.h
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
/**
* A simple logger
*
* User should define clog_level macro or variable first.
* Example:
* int clog_level = CL_MAX; log all message
* #define clog_level CL_NONE; to be quiet
*/
#ifndef CLOG_H
#define CLOG_H
#include <stdlib.h>
#ifndef ARCH_CLOG
#define die(fmt, ...) do { \
fprintf(stderr, "%s-%s: " fmt, \
__func__, __FILE__, \
##__VA_ARGS__); \
exit(1); \
} while (0)
#define clog(level, fmt, ...) do { \
if (level <= clog_level) \
fprintf(stderr, fmt, \
##__VA_ARGS__); \
} while (0)
#else
extern void die(const char *fmt, ...);
extern void clog(int level, const char *fmt, ...);
#endif /* !def ARCH_LOG */
enum {
CL_ERROR = 0,
CL_WARN,
CL_INFO,
CL_DEBUG,
CL_DEBUG_V,
CL_MAX = CL_DEBUG_V,
CL_NONE = -1,
};
#endif