trace/debug logs are unlikely

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-02-13 04:11:41 +00:00
parent 2d56b77853
commit bb7466fc68
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
1 changed files with 9 additions and 2 deletions

View File

@ -17,14 +17,21 @@ enum log_level {
LOG_LEVEL_FATAL, LOG_LEVEL_FATAL,
}; };
#define LOG_UNLIKELY(level, x, ...) \
do { \
if (unlikely(LOG_LEVEL_##level >= log_get_level_tls())) { \
log_printf(tls_logger, LOG_LEVEL_##level, __func__, x, ##__VA_ARGS__); \
} \
} while (0)
#define LOG(level, x, ...) \ #define LOG(level, x, ...) \
do { \ do { \
if (LOG_LEVEL_##level >= log_get_level_tls()) { \ if (LOG_LEVEL_##level >= log_get_level_tls()) { \
log_printf(tls_logger, LOG_LEVEL_##level, __func__, x, ##__VA_ARGS__); \ log_printf(tls_logger, LOG_LEVEL_##level, __func__, x, ##__VA_ARGS__); \
} \ } \
} while (0) } while (0)
#define log_trace(x, ...) LOG(TRACE, x, ##__VA_ARGS__) #define log_trace(x, ...) LOG_UNLIKELY(TRACE, x, ##__VA_ARGS__)
#define log_debug(x, ...) LOG(DEBUG, x, ##__VA_ARGS__) #define log_debug(x, ...) LOG_UNLIKELY(DEBUG, x, ##__VA_ARGS__)
#define log_info(x, ...) LOG(INFO, x, ##__VA_ARGS__) #define log_info(x, ...) LOG(INFO, x, ##__VA_ARGS__)
#define log_warn(x, ...) LOG(WARN, x, ##__VA_ARGS__) #define log_warn(x, ...) LOG(WARN, x, ##__VA_ARGS__)
#define log_error(x, ...) LOG(ERROR, x, ##__VA_ARGS__) #define log_error(x, ...) LOG(ERROR, x, ##__VA_ARGS__)