log.h
Go to the documentation of this file.
1 #ifndef NVIM_LOG_H
2 #define NVIM_LOG_H
3 
4 #include <stdio.h>
5 #include <stdbool.h>
6 
7 #define DEBUG_LOG_LEVEL 0
8 #define INFO_LOG_LEVEL 1
9 #define WARN_LOG_LEVEL 2
10 #define ERROR_LOG_LEVEL 3
11 
12 #define DLOG(...)
13 #define DLOGN(...)
14 #define ILOG(...)
15 #define ILOGN(...)
16 #define WLOG(...)
17 #define WLOGN(...)
18 #define ELOG(...)
19 #define ELOGN(...)
20 
21 #ifndef MIN_LOG_LEVEL
22 # define MIN_LOG_LEVEL INFO_LOG_LEVEL
23 #endif
24 
25 #define LOG(level, ...) logmsg((level), NULL, __func__, __LINE__, true, \
26  __VA_ARGS__)
27 
28 #if MIN_LOG_LEVEL <= DEBUG_LOG_LEVEL
29 # undef DLOG
30 # undef DLOGN
31 # define DLOG(...) logmsg(DEBUG_LOG_LEVEL, NULL, __func__, __LINE__, true, \
32  __VA_ARGS__)
33 # define DLOGN(...) logmsg(DEBUG_LOG_LEVEL, NULL, __func__, __LINE__, false, \
34  __VA_ARGS__)
35 #endif
36 
37 #if MIN_LOG_LEVEL <= INFO_LOG_LEVEL
38 # undef ILOG
39 # undef ILOGN
40 # define ILOG(...) logmsg(INFO_LOG_LEVEL, NULL, __func__, __LINE__, true, \
41  __VA_ARGS__)
42 # define ILOGN(...) logmsg(INFO_LOG_LEVEL, NULL, __func__, __LINE__, false, \
43  __VA_ARGS__)
44 #endif
45 
46 #if MIN_LOG_LEVEL <= WARN_LOG_LEVEL
47 # undef WLOG
48 # undef WLOGN
49 # define WLOG(...) logmsg(WARN_LOG_LEVEL, NULL, __func__, __LINE__, true, \
50  __VA_ARGS__)
51 # define WLOGN(...) logmsg(WARN_LOG_LEVEL, NULL, __func__, __LINE__, false, \
52  __VA_ARGS__)
53 #endif
54 
55 #if MIN_LOG_LEVEL <= ERROR_LOG_LEVEL
56 # undef ELOG
57 # undef ELOGN
58 # define ELOG(...) logmsg(ERROR_LOG_LEVEL, NULL, __func__, __LINE__, true, \
59  __VA_ARGS__)
60 # define ELOGN(...) logmsg(ERROR_LOG_LEVEL, NULL, __func__, __LINE__, false, \
61  __VA_ARGS__)
62 #endif
63 
64 #ifdef HAVE_EXECINFO_BACKTRACE
65 # define LOG_CALLSTACK() log_callstack(__func__, __LINE__)
66 # define LOG_CALLSTACK_TO_FILE(fp) log_callstack_to_file(fp, __func__, __LINE__)
67 #endif
68 
69 #ifdef INCLUDE_GENERATED_DECLARATIONS
70 # include "log.h.generated.h"
71 #endif
72 #endif // NVIM_LOG_H