日志_测试代码_Qt532

时间:2024-05-24 14:37:50

1、

int LogFile(QString &_str)
{
QDateTime datetime = QDateTime::currentDateTime();//获取系统现在的时间
QString strTime = datetime.toString("hh:mm:ss.zzz"); //设置显示格式 #ifdef BUILD_EXE
QString strExeDll = "[EXE]";
#else
QString strExeDll = "[DLL]";
#endif
_str = strTime+" : "+ strExeDll +" "+_str+ "\r\n";
// ZC: 本exe所在路径
QString strPath;
QDir dir;
strPath = dir.currentPath(); QString strDate = datetime.toString("yyyyMMdd"); //设置显示格式 // ZC: log文件的 路径 及 文件名
QString strLogFileName = strPath+"/"+strDate+".log"; HANDLE hLogFile = CreateFileA(strLogFileName.toLatin1(), GENERIC_WRITE, FILE_SHARE_READ, , OPEN_ALWAYS/*CREATE_NEW*/, , );
if (hLogFile == INVALID_HANDLE_VALUE)
return GetLastError(); //BOOL B = SetEndOfFile(hLogFile);
if ( INVALID_SET_FILE_POINTER == SetFilePointer(hLogFile, , , FILE_END) )
{
int iErr = GetLastError();
CloseHandle(hLogFile);
return iErr;
}
DWORD dwWritten = ;
BOOL B = WriteFile(hLogFile, _str.toLatin1(), _str.length(), &dwWritten, NULL);
if (! B)
{
int iErr = GetLastError();
CloseHandle(hLogFile);
return iErr;
}
CloseHandle(hLogFile);
return ;
}

2、

3、

相关文章