-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.h
73 lines (63 loc) · 1.34 KB
/
debug.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* debugging macros
* heavily inspired by previous work and Internet resources
*
* uses C99 variadic macros
* uses non-standard usage of the token-paste operator (##) for
* removing the comma symbol (,) when not followed by a token
* uses non-standard __FUNCTION__ macro (MSVC doesn't support __func__)
* tested on gcc 4.4.5 and Visual Studio 2008 (9.0), compiler version 15.00
*
* 2011, Razvan Deaconescu, [email protected]
*/
#ifndef DEBUG_H_
#define DEBUG_H_ 1
#ifdef __cplusplus
extern "C" {
#endif
#define DEBUG
#include <stdio.h>
/* log levels */
enum {
LOG_EMERG = 1,
LOG_ALERT,
LOG_CRIT,
LOG_ERR,
LOG_WARNING,
LOG_NOTICE,
LOG_INFO,
LOG_DEBUG
};
/*
* initialize default loglevel (for dlog)
* may be redefined in the including code
*/
#ifndef LOG_LEVEL
#define LOG_LEVEL LOG_DEBUG
#endif
/*
* define DEBUG macro as a compiler option:
* -DDEBUG for GCC
* /DDEBUG for MSVC
*/
#if defined DEBUG
#define dprintf(format, ...) \
fprintf(stderr, " [%s(), %s:%u] " format, \
__FUNCTION__, __FILE__, __LINE__, \
##__VA_ARGS__)
#else
#define dprintf(format, ...)
#endif
#if defined DEBUG
#define dlog(level, format, ...) \
do { \
if (level <= LOG_LEVEL) \
dprintf(format, ##__VA_ARGS__); \
} while (0)
#else
#define dlog(level, format, ...)
#endif
#ifdef __cplusplus
}
#endif
#endif