mcl_log_util.h
Go to the documentation of this file.
1 
11 #ifndef MCL_LOG_UTIL_H_
12 #define MCL_LOG_UTIL_H_
13 
15 
16 #ifdef __cplusplus
17 extern "C"
18 {
19 #endif
20 
31 typedef void (*mcl_log_util_callback_t)(void *user_context, int log_level, const char *file, int line, const char *tag, const char * const format, ...);
32 
46 
69 
79 
80 #define MCL_LOG_ENABLED_COMPILE_TIME(level) ((level) >= MCL_LOG_LEVEL)
81 #define MCL_LOG_ENABLED_RUN_TIME(level) ((level) >= mcl_log_util_get_output_level())
82 #define MCL_LOG_DISABLED (!MCL_LOG_ENABLED_COMPILE_TIME(MCL_LOG_LEVEL_FATAL))
83 
84 #define MCL_LOG_TAG_DEFAULT "[..]"
85 #define MCL_LOG_TAG_ENTRY "[->]"
86 #define MCL_LOG_TAG_LEAVE "[<-]"
87 
88 #if(MCL_LOG_DISABLED)
89 #define MCL_LOG_WRITE(...)
90 #else
93 
94 #define MCL_LOG_WRITE(level, tag, ...) \
95  do { \
96  if (MCL_LOG_ENABLED_RUN_TIME(level) && NULL != mcl_log_util_function) \
97  mcl_log_util_function(mcl_log_util_user_context, level, __FILE__, __LINE__, tag, __VA_ARGS__); \
98  } while(0)
99 #endif
100 
101 #if MCL_LOG_ENABLED_COMPILE_TIME(MCL_LOG_LEVEL_VERBOSE)
102 #define MCL_VERBOSE(...) MCL_LOG_WRITE(MCL_LOG_LEVEL_VERBOSE, MCL_LOG_TAG_DEFAULT, __VA_ARGS__)
103 #define MCL_VERBOSE_ENTRY(...) MCL_LOG_WRITE(MCL_LOG_LEVEL_VERBOSE, MCL_LOG_TAG_ENTRY, __VA_ARGS__)
104 #define MCL_VERBOSE_LEAVE(...) MCL_LOG_WRITE(MCL_LOG_LEVEL_VERBOSE, MCL_LOG_TAG_LEAVE, __VA_ARGS__)
105 #define MCL_VERBOSE_STRING(string) MCL_VERBOSE("%s", string)
106 #else
107 #define MCL_VERBOSE(...)
108 #define MCL_VERBOSE_ENTRY(...)
109 #define MCL_VERBOSE_LEAVE(...)
110 #define MCL_VERBOSE_STRING(string)
111 #endif
112 
113 #if MCL_LOG_ENABLED_COMPILE_TIME(MCL_LOG_LEVEL_DEBUG)
114 #define MCL_DEBUG(...) MCL_LOG_WRITE(MCL_LOG_LEVEL_DEBUG, MCL_LOG_TAG_DEFAULT, __VA_ARGS__)
115 #define MCL_DEBUG_ENTRY(...) MCL_LOG_WRITE(MCL_LOG_LEVEL_DEBUG, MCL_LOG_TAG_ENTRY, __VA_ARGS__)
116 #define MCL_DEBUG_LEAVE(...) MCL_LOG_WRITE(MCL_LOG_LEVEL_DEBUG, MCL_LOG_TAG_LEAVE, __VA_ARGS__)
117 #define MCL_DEBUG_STRING(string) MCL_DEBUG("%s", string)
118 #else
119 #define MCL_DEBUG(...)
120 #define MCL_DEBUG_ENTRY(...)
121 #define MCL_DEBUG_LEAVE(...)
122 #define MCL_DEBUG_STRING(string)
123 #endif
124 
125 #if MCL_LOG_ENABLED_COMPILE_TIME(MCL_LOG_LEVEL_INFO)
126 #define MCL_INFO(...) MCL_LOG_WRITE(MCL_LOG_LEVEL_INFO, MCL_LOG_TAG_DEFAULT, __VA_ARGS__)
127 #define MCL_INFO_STRING(string) MCL_INFO("%s", string)
128 #else
129 #define MCL_INFO(...)
130 #define MCL_INFO_STRING(string)
131 #endif
132 
133 #if MCL_LOG_ENABLED_COMPILE_TIME(MCL_LOG_LEVEL_WARN)
134 #define MCL_WARN(...) MCL_LOG_WRITE(MCL_LOG_LEVEL_WARN, MCL_LOG_TAG_DEFAULT, __VA_ARGS__)
135 #define MCL_WARN_STRING(string) MCL_WARN("%s", string)
136 #else
137 #define MCL_WARN(...)
138 #define MCL_WARN_STRING(string)
139 #endif
140 
141 #if MCL_LOG_ENABLED_COMPILE_TIME(MCL_LOG_LEVEL_ERROR)
142 #define MCL_ERROR(...) MCL_LOG_WRITE(MCL_LOG_LEVEL_ERROR, MCL_LOG_TAG_DEFAULT, __VA_ARGS__)
143 #define MCL_ERROR_STRING(string) MCL_ERROR("%s", string)
144 #else
145 #define MCL_ERROR(...)
146 #define MCL_ERROR_STRING(string)
147 #endif
148 
149 #if MCL_LOG_ENABLED_COMPILE_TIME(MCL_LOG_LEVEL_FATAL)
150 #define MCL_FATAL(...) MCL_LOG_WRITE(MCL_LOG_LEVEL_FATAL, MCL_LOG_TAG_DEFAULT, __VA_ARGS__)
151 #define MCL_FATAL_STRING(string) MCL_FATAL("%s", string)
152 #else
153 #define MCL_FATAL(...)
154 #define MCL_FATAL_STRING(string)
155 #endif
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif //MCL_LOG_UTIL_H_
mcl_int32_t mcl_error_t
MCL_CORE_EXPORT mcl_error_t mcl_log_util_set_output_level(const int log_level)
Definition: log_util.c:33
MCL_CORE_EXPORT mcl_log_util_callback_t mcl_log_util_function
Definition: log_util.c:19
MCL_CORE_EXPORT void * mcl_log_util_user_context
Definition: log_util.c:20
#define MCL_CORE_EXPORT
MCL_CORE_EXPORT int mcl_log_util_get_output_level(void)
Definition: log_util.c:51
Common module interface header file.
MCL_CORE_EXPORT mcl_error_t mcl_log_util_set_callback(mcl_log_util_callback_t callback, void *user_context)
Definition: log_util.c:60
void(* mcl_log_util_callback_t)(void *user_context, int log_level, const char *file, int line, const char *tag, const char *const format,...)
Definition: mcl_log_util.h:31