perf: 将MESA_handle_runtime_log封装为宏函数,先判断日志级别再拼接字符串

This commit is contained in:
luwenpeng
2023-05-31 14:05:09 +08:00
parent 0973d8c35a
commit 9032f13bbf

View File

@@ -48,16 +48,44 @@
extern void * g_default_logger;
extern bool g_print_to_stderr;
#define TFE_LOG_ERROR(handler, fmt, ...) \
do { if(g_print_to_stderr) fprintf(stderr, fmt "\n" , ##__VA_ARGS__); \
MESA_handle_runtime_log((struct log_handle_t *)handler, RLOG_LV_FATAL, __FUNCTION__, fmt, ##__VA_ARGS__); } while(0)
#define TFE_LOG_ERROR(handler, fmt, ...) \
do \
{ \
if (g_print_to_stderr) \
{ \
fprintf(stderr, fmt "\n", ##__VA_ARGS__); \
} \
if (MESA_handle_runtime_log_level_enabled(handler, RLOG_LV_FATAL)) \
{ \
MESA_handle_runtime_log(handler, RLOG_LV_FATAL, __FUNCTION__, fmt, ##__VA_ARGS__); \
} \
} while (0)
#define TFE_LOG_INFO(handler, fmt, ...) \
do { if(g_print_to_stderr) fprintf(stderr, fmt "\n", ##__VA_ARGS__); \
MESA_handle_runtime_log((struct log_handle_t *)handler, RLOG_LV_INFO, __FUNCTION__, fmt, ##__VA_ARGS__); } while(0) \
#define TFE_LOG_INFO(handler, fmt, ...) \
do \
{ \
if (g_print_to_stderr) \
{ \
fprintf(stderr, fmt "\n", ##__VA_ARGS__); \
} \
if (MESA_handle_runtime_log_level_enabled(handler, RLOG_LV_INFO)) \
{ \
MESA_handle_runtime_log(handler, RLOG_LV_INFO, __FUNCTION__, fmt, ##__VA_ARGS__); \
} \
} while (0)
#define TFE_LOG_DEBUG(handler, fmt, ...) \
do { MESA_handle_runtime_log((struct log_handle_t *)handler, RLOG_LV_DEBUG, __FUNCTION__, fmt, ##__VA_ARGS__); } while(0) \
#define TFE_LOG_DEBUG(handler, fmt, ...) \
do \
{ \
if (g_print_to_stderr) \
{ \
fprintf(stderr, fmt "\n", ##__VA_ARGS__); \
} \
if (MESA_handle_runtime_log_level_enabled(handler, RLOG_LV_DEBUG)) \
{ \
MESA_handle_runtime_log(handler, RLOG_LV_DEBUG, __FUNCTION__, fmt, ##__VA_ARGS__); \
} \
} while (0)
#define CHECK_OR_EXIT(condition, fmt, ...) \
do { if(!(condition)) { TFE_LOG_ERROR(g_default_logger, fmt, ##__VA_ARGS__); exit(EXIT_FAILURE); } } while(0) \