diff --git a/common/include/tfe_utils.h b/common/include/tfe_utils.h index baaefb8..cc9dd37 100644 --- a/common/include/tfe_utils.h +++ b/common/include/tfe_utils.h @@ -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) \