-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog.h
45 lines (36 loc) · 765 Bytes
/
log.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
/**
* log.h
* Copyright (C) 2012 Jan Viktorin
*/
#ifndef LOG_H
#define LOG_H
#define LOG_CGP 0x01
#ifndef LOG_MASK
#define LOG_MASK 0
#endif
#include <stdarg.h>
#define log_enabled(level) (LOG_MASK & (level))
#define log(level, fmt, ...) if(log_enabled(level)) {x__log(level, fmt, __VA_ARGS__);}
#define log_call(level) if(log_enabled(level)) {x__log(level, \
"%s#%s:%d", __FILE__, __func__, __LINE__);}
static
const char *x__level_as_str(int l)
{
switch(l) {
case LOG_CGP:
return "CGP";
default:
return "???";
}
}
static inline
void x__log(int level, const char *fmt, ...)
{
fprintf(stderr, "[%s] ", x__level_as_str(level));
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "\n");
}
#endif