diff options
| author | yangwei <[email protected]> | 2023-05-30 18:35:20 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2023-05-30 18:35:20 +0800 |
| commit | 8680c2f4f5639dbdabfa383b1d0819aabd7cc652 (patch) | |
| tree | 4e1ff396eba733bbcb41e34ff9531a93357bf926 /src | |
| parent | c0620c8d25bea170a5a75334c949435e1604b13d (diff) | |
✨ feat(MESA_handle_runtime_log_level_enabled): log_handle_t改为前置声明,增加判断level是否启用的接口
Diffstat (limited to 'src')
| -rw-r--r-- | src/MESA_handle_logger.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/src/MESA_handle_logger.c b/src/MESA_handle_logger.c index 473361c..93da94c 100644 --- a/src/MESA_handle_logger.c +++ b/src/MESA_handle_logger.c @@ -14,13 +14,13 @@ static int g_zlog_conf_fp = -1; static char global_conf_filepath[MAX_HANDLE_LOG_PATH] = ""; static char tmp_conf_filepath[MAX_HANDLE_LOG_PATH] = ""; -typedef struct log_handle_t +struct log_handle_t { int runtime_log_level; zlog_category_t *zc; const char *global_conf_path; char runtime_log_file[MAX_HANDLE_LOG_PATH]; -} log_handle_t; +}; @@ -163,7 +163,7 @@ static void snapshot_handle_info(const char *handle_name, const char *log_path, return; } -void *MESA_create_runtime_log_handle(const char *file_path, int level) +struct log_handle_t *MESA_create_runtime_log_handle(const char *file_path, int level) { if(file_path == NULL) return NULL; @@ -171,11 +171,11 @@ void *MESA_create_runtime_log_handle(const char *file_path, int level) int rc = -1; zlog_category_t *zc = NULL; FILE *fp = NULL; - log_handle_t *p_handle = NULL; + struct log_handle_t *handle = NULL; char handle_name[MAX_HANDLE_LOG_PATH]; char *p_path_end = rindex(file_path, '/'); - char *p_name = p_path_end+1; + char *p_name; strcpy(handle_name, file_path); escape_for_zlog(handle_name, strlen(handle_name)); @@ -195,14 +195,14 @@ void *MESA_create_runtime_log_handle(const char *file_path, int level) { fprintf(stderr,"[MESA_create_runtime_log_handle], get zlog category (%s) in global_conf_filepath(%s) fail\n", p_name, global_conf_filepath); } - p_handle = (log_handle_t *)calloc(sizeof(log_handle_t), 1); - strncpy(p_handle->runtime_log_file, file_path, sizeof(p_handle->runtime_log_file) - 1); - p_handle->runtime_log_level = level; - p_handle->zc = zc; - return (void *)p_handle; + handle = (struct log_handle_t *)calloc(sizeof(struct log_handle_t), 1); + strncpy(handle->runtime_log_file, file_path, sizeof(handle->runtime_log_file) - 1); + handle->runtime_log_level = level; + handle->zc = zc; + return (void *)handle; } -void MESA_destroy_runtime_log_handle(void *handle) +void MESA_destroy_runtime_log_handle(struct log_handle_t *handle) { if(handle != NULL) { @@ -214,18 +214,23 @@ void MESA_destroy_runtime_log_handle(void *handle) } -void MESA_handle_runtime_log(void *handle, int level, const char *module, const char *fmt, ...) +int MESA_handle_runtime_log_level_enabled(struct log_handle_t *handle, const int level) { - - log_handle_t *p_handle = (log_handle_t *)handle; + if(handle == NULL || handle->runtime_log_file == NULL)return; + if(handle->zc == NULL) return; + return zlog_level_enabled(handle->zc, level); +} - if(p_handle == NULL || p_handle->runtime_log_file == NULL)return; +void MESA_handle_runtime_log(struct log_handle_t *handle, int level, const char *module, const char *fmt, ...) +{ + + if(handle == NULL || handle->runtime_log_file == NULL)return; - if(p_handle->zc == NULL)return; + if(handle->zc == NULL)return; va_list ap; va_start(ap, fmt); - vzlog(p_handle->zc, p_handle->runtime_log_file, strlen(p_handle->runtime_log_file), module, strlen(module), __LINE__, level, fmt, ap); + vzlog(handle->zc, handle->runtime_log_file, strlen(handle->runtime_log_file), module, strlen(module), __LINE__, level, fmt, ap); va_end(ap); return ; } |
