summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author杨威 <[email protected]>2019-09-24 14:03:54 +0800
committer杨威 <[email protected]>2019-09-24 14:03:54 +0800
commitdfd0b4efb793d6a2ca902e8102d7918b21539978 (patch)
tree2ba916a0a54bcbe6ce24ee4190750058da9baa12
parentcecbe2628d4467f807ed9ea0eb79e4fa8f97eaf2 (diff)
增加两个环境变量,HLOG_FLUSH_NUM和HLOG_MSG_SIZE,分别用于控制fflush文件的条数和单条log的最大长度,默认值分别为0和4096
如果有调整的需要,可以在进程运行时定义环境变量,作用范围为进程
-rw-r--r--.gitignore4
-rw-r--r--demo/test_handle_logger.c2
-rw-r--r--src/MESA_handle_logger.c11
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 <unistd.h>
#include<sys/stat.h>
-#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;