示例#1
0
static int32_t get_log_header(int32_t m, char *txt)
{
	struct s_client *cl = cur_client();
	struct tm lt;
	int32_t pos;

	cs_ftime(&log_ts);
	time_t walltime = cs_walltime(&log_ts);
	localtime_r(&walltime, &lt);

	pos = snprintf(txt, LOG_BUF_SIZE,  "[LOG000]%4d/%02d/%02d %02d:%02d:%02d ", lt.tm_year + 1900, lt.tm_mon + 1, lt.tm_mday, lt.tm_hour, lt.tm_min, lt.tm_sec);

	switch(m)
	{
	case 1: // Add thread id and reader type
		return pos + snprintf(txt + pos, LOG_BUF_SIZE - pos, "%8X %c ", cl ? cl->tid : 0, cl ? cl->typ : ' ');
	case 0: // Add thread id
		return pos + snprintf(txt + pos, LOG_BUF_SIZE - pos, "%8X%-3.3s ", cl ? cl->tid : 0, "");
	default: // Add empty thread id
		return pos + snprintf(txt + pos, LOG_BUF_SIZE - pos, "%8X%-3.3s ", 0, "");
	}
}
示例#2
0
/* Return real time clock value calculated based on cs_gettime(). Use this instead of time() */
time_t cs_time(void)
{
	struct timeb tb;
	cs_ftime(&tb);
	return cs_walltime(&tb);
}
示例#3
0
static uint8_t get_log_header(char *txt, int32_t txt_size, uint8_t* hdr_logcount_offset,
								uint8_t* hdr_date_offset, uint8_t* hdr_time_offset, uint8_t* hdr_info_offset)
{
	struct s_client *cl = cur_client();
	struct tm lt;
	int32_t tmp;
		
	cs_ftime(&log_ts);
	time_t walltime = cs_walltime(&log_ts);
	localtime_r(&walltime, &lt);

	tmp = snprintf(txt, txt_size,  "[LOG000]%04d/%02d/%02d %02d:%02d:%02d %08X %c ",
		lt.tm_year + 1900,
		lt.tm_mon + 1,
		lt.tm_mday,
		lt.tm_hour,
		lt.tm_min,
		lt.tm_sec,
		cl ? cl->tid : 0,
		cl ? cl->typ : ' '
	);
	
	if(tmp == 39)
	{
		if(hdr_logcount_offset != NULL)
		{
			// depends on snprintf(...) format
			(*hdr_logcount_offset) = 4;
		}
		if(hdr_date_offset != NULL)
		{
			// depends on snprintf(...) format
			(*hdr_date_offset) = *hdr_logcount_offset + 4;
		}
		if(hdr_time_offset != NULL)
		{
			// depends on snprintf(...) format
			(*hdr_time_offset) = *hdr_date_offset + 11;
		}
		if(hdr_info_offset != NULL)
		{
			// depends on snprintf(...) format
			(*hdr_info_offset) = *hdr_time_offset + 9;
		}
		
		return (uint8_t)tmp;
	}
	
	if(hdr_logcount_offset != NULL)
	{
		(*hdr_logcount_offset) = 0;
	}	
	if(hdr_date_offset != NULL)
	{
		(*hdr_date_offset) = 0;
	}
	if(hdr_time_offset != NULL)
	{
		(*hdr_time_offset) = 0;
	}
	if(hdr_info_offset != NULL)
	{
		(*hdr_info_offset) = 0;
	}	
	
	return 0;
}