From 7fa29b1a00b1d33c85f73686260d674b66ffb9e9 Mon Sep 17 00:00:00 2001 From: yangwei Date: Tue, 30 May 2023 18:59:08 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20perf(MESA=5Fhandle=5Fruntime=5Fl?= =?UTF-8?q?og):=20=E5=86=85=E9=83=A8=E5=A2=9E=E5=8A=A0=E5=88=A4=E6=96=ADle?= =?UTF-8?q?vel=E7=9A=84=E7=BA=A7=E5=88=AB=EF=BC=8C=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E5=AE=8F=E5=B1=95=E5=BC=80=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/MESA_handle_logger.h | 21 +++++++++++++++------ src/MESA_handle_logger.c | 24 ++++++++++++++---------- 2 files changed, 29 insertions(+), 16 deletions(-) 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 ; }