日志打印函数

void WriteUpdateLog(const char* strOutputString, ...)
{
char strBuffer[256] = {0};
SYSTEMTIME curTime;
CString strTime, strMsg;
FILE *pFile = NULL;

//获取系统当前时间,写入日志文件
GetLocalTime(&curTime);
strTime.Format("[%04d-%02d-%02d %02d:%02d:%02d.%03d] ", curTime.wYear, curTime.wMonth, curTime.wDay,
curTime.wHour, curTime.wMinute, curTime.wSecond, curTime.wMilliseconds);

if (pFile == NULL)
{
pFile = fopen(UPDATE_LOGFILE, "a");
}

if (pFile != NULL)
{
// 格式化信息输出
va_list vlArgs;
va_start(vlArgs, strOutputString);
_vsnprintf(strBuffer, sizeof(strBuffer)-1, strOutputString, vlArgs);
va_end(vlArgs);

strMsg.Format("%s%s", strTime, strBuffer);
fputs(strMsg.GetBuffer(), pFile);
fclose(pFile);
}
}

WriteUpdateLog("asd %s",str);

posted @ 2016-04-07 10:38  hellohyi  阅读(193)  评论(0编辑  收藏  举报