clibs
Tiny but handy utility libraries for C
clibs_logging.h
Go to the documentation of this file.
1
6
#ifndef CLIBS_LOGGING_H
7
#define CLIBS_LOGGING_H
8
9
#include <stdio.h>
10
#include <stdlib.h>
11
12
#define CLIBS_LOG_LEVEL_DEBUG 5
13
#define CLIBS_LOG_LEVEL_INFO 4
14
#define CLIBS_LOG_LEVEL_WARN 3
15
#define CLIBS_LOG_LEVEL_ERROR 2
16
#define CLIBS_LOG_LEVEL_FATAL 1
17
#define CLIBS_LOG_LEVEL_NONE 0
18
25
#if DEBUG
26
#define CLIBS_LOG_LEVEL CLIBS_LOG_LEVEL_DEBUG
27
#elif INFO
28
#define CLIBS_LOG_LEVEL CLIBS_LOG_LEVEL_INFO
29
#elif WARN
30
#define CLIBS_LOG_LEVEL CLIBS_LOG_LEVEL_WARN
31
#elif ERROR
32
#define CLIBS_LOG_LEVEL CLIBS_LOG_LEVEL_ERROR
33
#elif FATAL
34
#define CLIBS_LOG_LEVEL CLIBS_LOG_LEVEL_FATAL
35
#else
36
#define CLIBS_LOG_LEVEL CLIBS_LOG_LEVEL_NONE
37
#endif
38
39
#ifndef END_OF_LINE
40
#define END_OF_LINE "\n"
41
#endif
42
49
#if CLIBS_LOG_LEVEL >= CLIBS_LOG_LEVEL_DEBUG
50
#define CLIBS_LOG_DEBUG(format, ...) { \
51
fprintf(stderr, "[DEBUG] (%s:%d) " format "%s", \
52
__FILE__, __LINE__, ##__VA_ARGS__, END_OF_LINE); \
53
}
54
#else
55
#define CLIBS_LOG_DEBUG(format, ...)
56
#endif
57
64
#if CLIBS_LOG_LEVEL >= CLIBS_LOG_LEVEL_INFO
65
#define CLIBS_LOG_INFO(format, ...) { \
66
fprintf(stderr, "[INFO] " format "%s", \
67
##__VA_ARGS__, END_OF_LINE); \
68
}
69
#else
70
#define CLIBS_LOG_INFO(format, ...)
71
#endif
72
79
#if CLIBS_LOG_LEVEL >= CLIBS_LOG_LEVEL_WARN
80
#define CLIBS_LOG_WARN(format, ...) { \
81
fprintf(stderr, "[WARN] " format "%s", \
82
##__VA_ARGS__, END_OF_LINE); \
83
}
84
#else
85
#define CLIBS_LOG_WARN(format, ...)
86
#endif
87
94
#if CLIBS_LOG_LEVEL >= CLIBS_LOG_LEVEL_ERROR
95
#define CLIBS_LOG_ERROR(format, ...) { \
96
fprintf(stderr, "[ERROR] " format "%s", \
97
##__VA_ARGS__, END_OF_LINE); \
98
exit(1); \
99
}
100
#else
101
#define CLIBS_LOG_ERROR(format, ...)
102
#endif
103
110
#if CLIBS_LOG_LEVEL >= CLIBS_LOG_LEVEL_FATAL
111
#define CLIBS_LOG_FATAL(format, ...) { \
112
fprintf(stderr, "[FATAL] " format "%s", \
113
##__VA_ARGS__, END_OF_LINE); \
114
abort(); \
115
}
116
#else
117
#define CLIBS_LOG_FATAL(format, ...)
118
#endif
119
120
#endif
/* CLIBS_LOGGING_H */
Generated by
1.8.13