diff options
| author | yangwei <[email protected]> | 2020-09-03 11:00:17 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2020-09-03 11:00:17 +0800 |
| commit | 6ae5d5ffa9abc449e103c82c2fc5ac1507e4e5b2 (patch) | |
| tree | 288f613189108fe85f30ca99f8690d033fc4ee1b | |
| parent | 1f9fc661527609dc5100fbbec44fc03b80c6c4d0 (diff) | |
1、Update 默认rules后面带level,而不是*
2、带pathvar初始化失败后,直接结束zlog,而不是跳转至error避免操作不存在的conf_file
3、创建句柄中的zlog_get_category失败后,返回句柄中zc为空,之后写入日志操作中判断zc,如果为null,直接返回,用于适配无rules即等效于关闭日志的场景
| -rw-r--r-- | src/MESA_handle_logger.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/MESA_handle_logger.c b/src/MESA_handle_logger.c index 56376a4..8da9752 100644 --- a/src/MESA_handle_logger.c +++ b/src/MESA_handle_logger.c @@ -186,8 +186,8 @@ void *MESA_create_runtime_log_handle(const char *file_path, int level) goto error; } snprintf(zlog_rule_conf_content, sizeof(zlog_rule_conf_content), - "[global]\ndefault format = \"%%d(%%c), %%V, %%m%%n\" \n[levels]\nDEBUG=10\nINFO=20\nFATAL=30\n[rules]\n%s.* \"%s.%%d(%%F)\"", - p_name, file_path); + "[global]\ndefault format = \"%%d(%%c), %%V, %%m%%n\" \n[levels]\nDEBUG=10\nINFO=20\nFATAL=30\n[rules]\n%s.%d \"%s.%%d(%%F)\"", + p_name, level, file_path); write(g_zlog_conf_fp, zlog_rule_conf_content, strlen(zlog_rule_conf_content)); fsync(g_zlog_conf_fp); int rc = zlog_init(tmp_conf_filepath); @@ -210,6 +210,7 @@ void *MESA_create_runtime_log_handle(const char *file_path, int level) } else { + zc = zlog_get_category(p_name); if (!zc) { @@ -221,8 +222,8 @@ void *MESA_create_runtime_log_handle(const char *file_path, int level) //if (get_filepath(g_zlog_conf_fp, tmp_conf_filepath, sizeof(tmp_conf_filepath)) < 0) // return NULL; snprintf(zlog_rule_conf_content, sizeof(zlog_rule_conf_content), - "\n%s.* \"%s.%%d(%%F)\"", - p_name, file_path); + "\n%s.%d \"%s.%%d(%%F)\"", + p_name, level, file_path); write(g_zlog_conf_fp, zlog_rule_conf_content, strlen(zlog_rule_conf_content)); fsync(g_zlog_conf_fp); int rc = zlog_reload(tmp_conf_filepath); @@ -240,7 +241,10 @@ void *MESA_create_runtime_log_handle(const char *file_path, int level) { zc = init_zlog(pathvar, p_name); if (zc == NULL) - goto error; + { + zlog_fini(); + //return NULL; + } } 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); @@ -275,6 +279,8 @@ void MESA_handle_runtime_log(void *handle, int level, const char *module, const if(p_handle == NULL || p_handle->runtime_log_file == NULL)return; + if(p_handle->zc == NULL)return; + if(level < p_handle->runtime_log_level) return; va_list ap; |
