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);
原文:http://www.cnblogs.com/xuandi/p/5362408.html