From dfd0b4efb793d6a2ca902e8102d7918b21539978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=A8=81?= Date: Tue, 24 Sep 2019 14:03:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=A4=E4=B8=AA=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=EF=BC=8CHLOG=5FFLUSH=5FNUM=E5=92=8C?= =?UTF-8?q?HLOG=5FMSG=5FSIZE=EF=BC=8C=E5=88=86=E5=88=AB=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E6=8E=A7=E5=88=B6fflush=E6=96=87=E4=BB=B6=E7=9A=84=E6=9D=A1?= =?UTF-8?q?=E6=95=B0=E5=92=8C=E5=8D=95=E6=9D=A1log=E7=9A=84=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E9=95=BF=E5=BA=A6=EF=BC=8C=E9=BB=98=E8=AE=A4=E5=80=BC?= =?UTF-8?q?=E5=88=86=E5=88=AB=E4=B8=BA0=E5=92=8C4096?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 如果有调整的需要,可以在进程运行时定义环境变量,作用范围为进程 --- .gitignore | 4 ++++ demo/test_handle_logger.c | 2 +- src/MESA_handle_logger.c | 11 ++++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 0433f2f..647907e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,7 @@ build/ core.* version.txt demo/test_handle_logger +cmake-build-debug +GPATH +GRTAGS +GTAGS diff --git a/demo/test_handle_logger.c b/demo/test_handle_logger.c index 816d11c..448c14b 100644 --- a/demo/test_handle_logger.c +++ b/demo/test_handle_logger.c @@ -39,7 +39,7 @@ void call_logger(int log_num, int thread_num) { MESA_handle_runtime_log(sample_handle, RLOG_LV_INFO, "sample", "sample_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num); //sleep(1); - //MESA_handle_runtime_log(test_handle, RLOG_LV_INFO, "test", "test_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num); + MESA_handle_runtime_log(test_handle, RLOG_LV_INFO, "test", "test_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num); //MESA_HANDLE_RUNTIME_LOG(sample_handle, RLOG_LV_FATAL, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num); ////sleep(1); //MESA_HANDLE_RUNTIME_LOG(test_handle, RLOG_LV_FATAL, "test", "test_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num); diff --git a/src/MESA_handle_logger.c b/src/MESA_handle_logger.c index 7e7724c..84b0612 100644 --- a/src/MESA_handle_logger.c +++ b/src/MESA_handle_logger.c @@ -8,15 +8,15 @@ #include #include -#define LOGMSG_MAX_LEN 4096 -#define FLUSH_LOG_NUM 4096 +int LOGMSG_MAX_LEN = 4096; +int FLUSH_LOG_NUM = 0; typedef struct log_handle_t { int runtime_log_level; int flush_log_count; FILE *fp; char runtime_log_file[1200]; - char cur_log_file[LOGMSG_MAX_LEN]; + char cur_log_file[4096]; } log_handle_t; @@ -97,7 +97,12 @@ void *MESA_create_runtime_log_handle(const char *file_path, int level) { if(file_path == NULL) return NULL; + char *max_len = getenv("HLOG_MSG_SIZE"); + char *flush_num = getenv("HLOG_FLUSH_NUM"); + if(max_len != NULL)LOGMSG_MAX_LEN = atoi(max_len); + if(flush_num != NULL)FLUSH_LOG_NUM = atoi(flush_num); + FILE *fp = NULL; log_handle_t *p_handle = NULL;