948
社区成员
发帖
与我相关
我的任务
分享
static int Write(ILog* a_pMe,const char* pFormat,...)
{
#ifdef _DEBUG_
Loger* pMe=(Loger*)a_pMe;
IFile * pFile=pMe->m_pFile;
// declare time
JulianType pDate;
char* pTime;
// declare log content.
char* pLogContent;
char nn[1024];
va_list cArguments;
if (pFormat==NULL)
return EFAILED;
MEMSET(nn,0,1024);
//malloc of pointer.
pTime=(char*)MALLOC(sizeof(char)*SIZE);
pLogContent = (char*)MALLOC(sizeof(char)*SIZE);
// get current time and write into file.
GETJULIANDATE(0,&pDate);
SPRINTF(pTime,"[%4d-%02d-%02d %02d:%02d:%02d]:",pDate.wYear,pDate.wMonth,\
pDate.wDay,pDate.wHour,pDate.wMinute,pDate.wSecond);
IFILE_Write(pFile, pTime, STRLEN(pTime));
// 定位是这个地方出了问题!!但是不知道怎么解决
va_start(cArguments, pFormat);
VSPRINTF(pLogContent,pFormat,cArguments);
SPRINTF(nn,"%s",pLogContent);
IFILE_Write(pFile, pLogContent, STRLEN(pLogContent));
va_end(cArguments);
//free the pointer
FREEIF(pTime)
FREEIF(pLogContent);
//cut line.
IFILE_Write(pFile, "\r\n----------------\r\n", STRLEN("\r\n----------------\r\n"));
return SUCCESS;
#endif
}
va_start(cArguments, pFormat);
VSPRINTF(pLogContent,pFormat,cArguments);
SPRINTF(nn,"%s",pLogContent);
IFILE_Write(pFile, pLogContent, STRLEN(pLogContent));
va_end(cArguments);
va_start(cArguments,pFormat);
do
{
c =*pFormat;
if (c != '%')
{
SPRINTF(StringChar,"%c",c); //照原样输出字符
STRCAT (finalString,StringChar);
}
else
{
//按格式字符输出数据
switch(*++pFormat)
{
case'd':
temp=va_arg(cArguments,int);
SPRINTF(StringChar,"%d",temp);
STRCAT(finalString,StringChar);
break;
case's':
tempString= va_arg(cArguments,char*);
STRCAT(finalString,tempString);
break;
default:
break;
}
}
++pFormat;
MEMSET(StringChar,0,64);
}while (*pFormat != '\0');