-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathlogging.h
83 lines (74 loc) · 1.84 KB
/
logging.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
74
75
76
77
78
79
80
81
82
83
#ifndef __logging_h
#define __logging_h
/*
* __FUNCTION__ -> __func__
* * see: https://gcc.gnu.org/gcc-5/porting_to.html
*https://gcc.gnu.org/gcc-5/porting_to.html
*/
#include <stdio.h>
#undef PDEBUGX
#ifdef API_DEBUG
# define PDEBUGX(fmt, ...) do{ \
fprintf(stderr, "%s(): ", __func__); \
fprintf(stderr, fmt, ##__VA_ARGS__); \
fprintf(stderr, "\n"); \
} while(0)
/* The do - while loop allows several statements in the macro
* and reuires semicolon after the marco: PDEBUG("%s.\n", some_var);
* This makes PDEBUG to looke a function.
* do - while will probably be eliminated by the compiler optmisation.
*/
#else
# define PDEBUGX(fmt, ...)
#endif
#undef PDEBUG
#ifdef API_DEBUG
# define PDEBUG(fmt) do{ \
fprintf(stderr, "%s(): ", __func__); \
fprintf(stderr, fmt); \
fprintf(stderr, "\n"); \
} while(0)
#else
# define PDEBUG(fmt)
#endif
#undef PTRACEX
#ifdef API_TRACE
# define PTRACEX(fmt, ...) do{ \
fprintf(stderr, "%s(): ", __func__); \
fprintf(stderr, fmt, ##__VA_ARGS__); \
fprintf(stderr, "\n"); \
} while(0)
#else
# define PTRACEX(fmt, ...)
#endif
#undef PTRACE
#ifdef API_TRACE
# define PTRACE(fmt) do{ \
fprintf(stderr, "%s(): ", __func__); \
fprintf(stderr, fmt); \
fprintf(stderr, "\n"); \
} while(0)
#else
# define PTRACE(fmt)
#endif
#undef PERRORX
#ifdef API_ERROR
# define PERRORX(fmt, ...) do{ \
fprintf(stderr, "%s(): ", __func__); \
fprintf(stderr, fmt, ##__VA_ARGS__); \
fprintf(stderr, "\n"); \
} while(0)
#else
# define PERRORX(fmt, ...) /* not debugging: nothing */
#endif
#undef PERROR
#ifdef API_ERROR
# define PERROR(fmt) do{ \
fprintf(stderr, "%s(): ", __func__); \
fprintf(stderr, fmt); \
fprintf(stderr, "\n"); \
} while(0)
#else
# define PERROR(fmt) /* not debugging: nothing */
#endif
#endif