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