修复仅支持东八区时间的问题,使用localtime_r进行转换

This commit is contained in:
yangwei
2018-12-05 21:04:42 +06:00
committed by dump2file
parent f47f6d8bbf
commit 6c8af75e99
6 changed files with 20 additions and 15 deletions

View File

@@ -19,17 +19,19 @@ typedef struct log_handle_t
const int HANDLE_LOGGER_VERSION_20170816 = 1;
static unsigned int month_days[12] =
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static unsigned char weekday_str[7][4] =
{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
static unsigned char month_str[12][4] = {"Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
char *thread_safe_ctime(const time_t *tp, char *buf, int len)
{
unsigned int year, month, day, weekday, hour, min, sec;
unsigned int year_days = 365;
unsigned int month_days[12] =
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static unsigned char weekday_str[7][4] =
{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
static unsigned char month_str[12][4] = {"Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
sec = * tp;
min = sec / 60; sec = sec % 60;
hour = min / 60; min = min % 60; hour += 8;
@@ -164,8 +166,11 @@ void MESA_handle_runtime_log(void *handle, int level, const char *module, const
if(level < p_handle->runtime_log_level) return;
time(&t);
THREAD_CTIME(&t, buf, LOGMSG_MAX_LEN);
len = strlen(buf);
if(NULL == (localtime_r(&t, &local_time))) return;
//THREAD_CTIME(&t, buf, LOGMSG_MAX_LEN);
len = snprintf(buf, sizeof(buf), "%s %s %d %02d:%02d:%02d %d", weekday_str[local_time.tm_wday],
month_str[local_time.tm_mon], local_time.tm_mday, local_time.tm_hour, local_time.tm_min, local_time.tm_sec, local_time.tm_year+1900);
//len = strlen(buf);
switch(level)
{
@@ -204,7 +209,6 @@ void MESA_handle_runtime_log(void *handle, int level, const char *module, const
len += snprintf(buf + len, LOGMSG_MAX_LEN - len, "\n");
if(NULL == (localtime_r(&t, &local_time))) return;
sprintf(tmp_log_file_name, "%s.%04d-%02d-%02d", p_handle->runtime_log_file,
local_time.tm_year + 1900, local_time.tm_mon + 1,