@@ -8,14 +8,18 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include<sys/stat.h>
|
#include<sys/stat.h>
|
||||||
|
|
||||||
|
#define LOGMSG_MAX_LEN 4096
|
||||||
|
#define FLUSH_LOG_NUM 4096
|
||||||
typedef struct log_handle_t
|
typedef struct log_handle_t
|
||||||
{
|
{
|
||||||
int runtime_log_level;
|
int runtime_log_level;
|
||||||
|
int flush_log_count;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char runtime_log_file[1200];
|
char runtime_log_file[1200];
|
||||||
|
char cur_log_file[LOGMSG_MAX_LEN];
|
||||||
} log_handle_t;
|
} log_handle_t;
|
||||||
|
|
||||||
#define LOGMSG_MAX_LEN 4096
|
|
||||||
|
|
||||||
//const int HANDLE_LOGGER_VERSION_20190218 = 1;
|
//const int HANDLE_LOGGER_VERSION_20190218 = 1;
|
||||||
|
|
||||||
@@ -201,12 +205,22 @@ void MESA_handle_runtime_log(void *handle, int level, const char *module, const
|
|||||||
local_time.tm_year + 1900, local_time.tm_mon + 1,
|
local_time.tm_year + 1900, local_time.tm_mon + 1,
|
||||||
local_time.tm_mday);
|
local_time.tm_mday);
|
||||||
|
|
||||||
|
OPEN_LOG_FILE:
|
||||||
if(p_handle->fp == NULL)
|
if(p_handle->fp == NULL)
|
||||||
{
|
{
|
||||||
if(NULL == (fp = fopen(tmp_log_file_name, "a"))) return;
|
if(NULL == (fp = fopen(tmp_log_file_name, "a"))) return;
|
||||||
|
|
||||||
p_handle->fp = fp;
|
p_handle->fp = fp;
|
||||||
|
p_handle->flush_log_count = 0;
|
||||||
|
memcpy(p_handle->cur_log_file, tmp_log_file_name, strlen(tmp_log_file_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (0 != memcmp(tmp_log_file_name, p_handle->cur_log_file, strlen(tmp_log_file_name)))
|
||||||
|
{
|
||||||
|
fclose(p_handle->fp);
|
||||||
|
p_handle->fp = NULL;
|
||||||
|
goto OPEN_LOG_FILE;
|
||||||
|
}
|
||||||
|
|
||||||
if (0 > fprintf(p_handle->fp, "%s", buf))
|
if (0 > fprintf(p_handle->fp, "%s", buf))
|
||||||
{
|
{
|
||||||
fclose(p_handle->fp);
|
fclose(p_handle->fp);
|
||||||
@@ -214,8 +228,14 @@ void MESA_handle_runtime_log(void *handle, int level, const char *module, const
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fflush(p_handle->fp);
|
p_handle->flush_log_count+=1;
|
||||||
}
|
if (p_handle->flush_log_count >= FLUSH_LOG_NUM)
|
||||||
|
{
|
||||||
|
fflush(p_handle->fp);
|
||||||
|
p_handle->flush_log_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user