log.h
Go to the documentation of this file.
1 #ifndef NVIM_LOG_H
2 #define NVIM_LOG_H
3 
4 #include <stdbool.h>
5 #include <stdio.h>
6 
7 #include "auto/config.h"
8 #include "nvim/macros.h"
9 
10 // USDT probes. Example invocation:
11 // NVIM_PROBE(nvim_foo_bar, 1, string.data);
12 #if defined(HAVE_SYS_SDT_H)
13 # include <sys/sdt.h> // NOLINT
14 # define NVIM_PROBE(name, n, ...) STAP_PROBE##n(neovim, name, __VA_ARGS__)
15 #else
16 # define NVIM_PROBE(name, n, ...)
17 #endif
18 
19 
20 #define TRACE_LOG_LEVEL 0
21 #define DEBUG_LOG_LEVEL 1
22 #define INFO_LOG_LEVEL 2
23 #define WARN_LOG_LEVEL 3
24 #define ERROR_LOG_LEVEL 4
25 
26 #define DLOG(...)
27 #define DLOGN(...)
28 #define ILOG(...)
29 #define ILOGN(...)
30 #define WLOG(...)
31 #define WLOGN(...)
32 #define ELOG(...)
33 #define ELOGN(...)
34 
35 #ifndef MIN_LOG_LEVEL
36 # define MIN_LOG_LEVEL INFO_LOG_LEVEL
37 #endif
38 
39 #define LOG(level, ...) logmsg((level), NULL, __func__, __LINE__, true, \
40  __VA_ARGS__)
41 
42 #if MIN_LOG_LEVEL <= DEBUG_LOG_LEVEL
43 # undef DLOG
44 # undef DLOGN
45 # define DLOG(...) logmsg(DEBUG_LOG_LEVEL, NULL, __func__, __LINE__, true, \
46  __VA_ARGS__)
47 # define DLOGN(...) logmsg(DEBUG_LOG_LEVEL, NULL, __func__, __LINE__, false, \
48  __VA_ARGS__)
49 #endif
50 
51 #if MIN_LOG_LEVEL <= INFO_LOG_LEVEL
52 # undef ILOG
53 # undef ILOGN
54 # define ILOG(...) logmsg(INFO_LOG_LEVEL, NULL, __func__, __LINE__, true, \
55  __VA_ARGS__)
56 # define ILOGN(...) logmsg(INFO_LOG_LEVEL, NULL, __func__, __LINE__, false, \
57  __VA_ARGS__)
58 #endif
59 
60 #if MIN_LOG_LEVEL <= WARN_LOG_LEVEL
61 # undef WLOG
62 # undef WLOGN
63 # define WLOG(...) logmsg(WARN_LOG_LEVEL, NULL, __func__, __LINE__, true, \
64  __VA_ARGS__)
65 # define WLOGN(...) logmsg(WARN_LOG_LEVEL, NULL, __func__, __LINE__, false, \
66  __VA_ARGS__)
67 #endif
68 
69 #if MIN_LOG_LEVEL <= ERROR_LOG_LEVEL
70 # undef ELOG
71 # undef ELOGN
72 # define ELOG(...) logmsg(ERROR_LOG_LEVEL, NULL, __func__, __LINE__, true, \
73  __VA_ARGS__)
74 # define ELOGN(...) logmsg(ERROR_LOG_LEVEL, NULL, __func__, __LINE__, false, \
75  __VA_ARGS__)
76 #endif
77 
78 #ifdef HAVE_EXECINFO_BACKTRACE
79 # define LOG_CALLSTACK() log_callstack(__func__, __LINE__)
80 # define LOG_CALLSTACK_TO_FILE(fp) log_callstack_to_file(fp, __func__, __LINE__)
81 #endif
82 
83 #if NVIM_HAS_INCLUDE("sanitizer/asan_interface.h")
84 # include "sanitizer/asan_interface.h"
85 #endif
86 
87 #ifdef INCLUDE_GENERATED_DECLARATIONS
88 # include "log.h.generated.h"
89 #endif
90 #endif // NVIM_LOG_H
macros.h