BOOL _WriteLog(FILE* pFileLog, char* pszFileName, CString strContents, char* pszFileMode)
{
return WriteLog(pFileLog, pszFileName, strContents, pszFileMode);
}
BOOL WriteLog(FILE* pFileLog, char* pszFileName, CString strContents, char* pszFileMode)
{
char szFileName[MAX_PATH] = {0};
SYSTEMTIME sysTime;
CString strTime;
CString strPath;
GetLocalTime(&sysTime);
strTime.Format("%04d-%02d-%02d %d %02d:%02d:%02d:%03d := ", sysTime.wYear,sysTime.wMonth,
sysTime.wDay,sysTime.wDayOfWeek,
sysTime.wHour,sysTime.wMinute,sysTime.wSecond,
sysTime.wMilliseconds);
GetModuleFileName(NULL,szFileName,MAX_PATH);
*strrchr(szFileName,'\\') = '\0';
strcat(szFileName, " \\log");
CreateDirectory(szFileName,NULL);
strPath.Format("%s\\%s.log",szFileName,pszFileName);
if(pFileLog == NULL)
{
pFileLog = fopen(strPath,pszFileMode);
if(pFileLog == NULL)
{
TRACE("write log failed!\n");
return FALSE;
}
}
g_pFileLog = pFileLog;
strContents = strTime + strContents + _T("\n");
fwrite(strContents,1,strContents.GetLength(),pFileLog);
return TRUE;
}