diff --git a/inc/MESA_handle_logger.h b/inc/MESA_handle_logger.h index 970e50d..49cee4a 100644 --- a/inc/MESA_handle_logger.h +++ b/inc/MESA_handle_logger.h @@ -19,8 +19,6 @@ extern "C" #define RLOG_LV_FATAL 30 -struct log_handle_t; - int MESA_handle_runtime_log_creation(const char *conf_path); int MESA_handle_runtime_log_reconstruction(const char *conf_path); void MESA_handle_runtime_log_destruction(); @@ -30,7 +28,18 @@ void MESA_handle_runtime_log_destruction(); __FILE__, __LINE__, ##args) -int MESA_handle_runtime_log_level_enabled(struct log_handle_t *handle, const int level); + +/* +#define MESA_HANDLE_RUNTIME_LOG_EXPAND(handle, level, module, fmt, ...) \ + { \ + if (MESA_handle_runtime_log_level_enabled(handle, level)) \ + { \ + MESA_handle_runtime_log(handle, level, module, fmt, __VA_ARGS__); \ + } \ + } +*/ + +int MESA_handle_runtime_log_level_enabled(void *handle, const int level); /* * name: MESA_create_runtime_log_handle * functionality: get runtime_log handle; @@ -41,7 +50,7 @@ int MESA_handle_runtime_log_level_enabled(struct log_handle_t *handle, const int * not NULL, if succeeded; * NULL, if file is not absolute path, or failed to create log file; */ -struct log_handle_t *MESA_create_runtime_log_handle(const char *file_path, int level); +void *MESA_create_runtime_log_handle(const char *file_path, int level); /* * name: MESA_handle_runtime_log @@ -55,7 +64,7 @@ struct log_handle_t *MESA_create_runtime_log_handle(const char *file_path, int l * returns: * none; */ -void MESA_handle_runtime_log(struct log_handle_t *handle, int level, const char *module, const char *fmt, ...); +void MESA_handle_runtime_log(void *handle, int level, const char *module, const char *fmt, ...); /* * name: MESA_destroy_runtime_log_handle @@ -65,7 +74,7 @@ void MESA_handle_runtime_log(struct log_handle_t *handle, int level, const char * returns: * none; */ -void MESA_destroy_runtime_log_handle(struct log_handle_t *handle); +void MESA_destroy_runtime_log_handle(void *handle); #ifdef __cplusplus } diff --git a/src/MESA_handle_logger.c b/src/MESA_handle_logger.c index 93da94c..d9b8274 100644 --- a/src/MESA_handle_logger.c +++ b/src/MESA_handle_logger.c @@ -163,7 +163,7 @@ static void snapshot_handle_info(const char *handle_name, const char *log_path, return; } -struct log_handle_t *MESA_create_runtime_log_handle(const char *file_path, int level) +void *MESA_create_runtime_log_handle(const char *file_path, int level) { if(file_path == NULL) return NULL; @@ -202,7 +202,7 @@ struct log_handle_t *MESA_create_runtime_log_handle(const char *file_path, int l return (void *)handle; } -void MESA_destroy_runtime_log_handle(struct log_handle_t *handle) +void MESA_destroy_runtime_log_handle(void *handle) { if(handle != NULL) { @@ -214,24 +214,28 @@ void MESA_destroy_runtime_log_handle(struct log_handle_t *handle) } -int MESA_handle_runtime_log_level_enabled(struct log_handle_t *handle, const int level) +int MESA_handle_runtime_log_level_enabled(void *v_handle, const int level) { - if(handle == NULL || handle->runtime_log_file == NULL)return; + struct log_handle_t *handle = (struct log_handle_t *)v_handle; + if(handle == NULL || handle->runtime_log_file == NULL)return; if(handle->zc == NULL) return; return zlog_level_enabled(handle->zc, level); } -void MESA_handle_runtime_log(struct log_handle_t *handle, int level, const char *module, const char *fmt, ...) +void MESA_handle_runtime_log(void *v_handle, int level, const char *module, const char *fmt, ...) { - + struct log_handle_t *handle = (struct log_handle_t *)handle; if(handle == NULL || handle->runtime_log_file == NULL)return; if(handle->zc == NULL)return; - va_list ap; - va_start(ap, fmt); - vzlog(handle->zc, handle->runtime_log_file, strlen(handle->runtime_log_file), module, strlen(module), __LINE__, level, fmt, ap); - va_end(ap); + if (zlog_level_enabled(handle->zc, level)) + { + va_list ap; + va_start(ap, fmt); + vzlog(handle->zc, handle->runtime_log_file, strlen(handle->runtime_log_file), module, strlen(module), __LINE__, level, fmt, ap); + va_end(ap); + } return ; }