You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
|
1 year ago
|
#include "WriteLog.h"
|
||
|
|
#include <stdarg.h>
|
||
|
|
#include <QString>
|
||
|
|
#include <QCoreApplication>
|
||
|
|
#include <QDir>
|
||
|
|
#include <QTextCodec>
|
||
|
|
|
||
|
|
|
||
|
|
//void WriteLogMiniNetwork(QString strLog)
|
||
|
|
//{
|
||
|
|
// if(logFileName_MiniNetWork.isEmpty()){
|
||
|
|
// QDir dir;
|
||
|
|
// logFileName_MiniNetWork = QCoreApplication::applicationDirPath();
|
||
|
|
// logFileName_MiniNetWork += "/log";
|
||
|
|
// dir.setPath(logFileName_MiniNetWork);
|
||
|
|
// if(!dir.exists()){
|
||
|
|
// dir.mkpath(logFileName_MiniNetWork);
|
||
|
|
// }
|
||
|
|
// logFileName_MiniNetWork += "/MiniNetwork.log";
|
||
|
|
// }
|
||
|
|
|
||
|
|
// //QByteArray baFileName = logFileName_MiniNetWork.toLocal8Bit();
|
||
|
|
// //QByteArray baLog = strLog.toLocal8Bit();
|
||
|
|
// WriteLog2(logFileName_MiniNetWork.toLocal8Bit().data(), strLog.toLocal8Bit().data(), 10, 10*1024*1024);
|
||
|
|
//}
|
||
|
|
|
||
|
|
|
||
|
|
void Write_Log(const QString &LogFileName, const QString &FileName, const QString &funcName, int iLine, const char *format, ...)
|
||
|
|
{
|
||
|
|
QString strLog;
|
||
|
|
va_list ap;
|
||
|
|
va_start(ap, format);
|
||
|
|
strLog = strLog.vasprintf(format, ap);
|
||
|
|
va_end(ap);
|
||
|
|
|
||
|
|
if(iLine != 0)
|
||
|
|
{
|
||
|
|
//带文件名称
|
||
|
|
#ifdef __WIN32
|
||
|
|
int iBegPos = FileName.lastIndexOf(QChar('\\'))+1;
|
||
|
|
int iEndPos = FileName.lastIndexOf(QChar('.'));
|
||
|
|
strLog = QString("[%1:%2:%3]").arg(FileName.mid(iBegPos, iEndPos - iBegPos)).arg(funcName).arg(iLine) + strLog;
|
||
|
|
#else
|
||
|
|
int iBegPos = FileName.lastIndexOf(QChar('/'))+1;
|
||
|
|
int iEndPos = FileName.lastIndexOf(QChar('.'));
|
||
|
|
strLog = QString("[%1:%2:%3]").arg(FileName.mid(iBegPos, iEndPos - iBegPos)).arg(funcName).arg(iLine) + strLog;
|
||
|
|
#endif
|
||
|
|
}else{
|
||
|
|
//不带文件名称
|
||
|
|
//strLog = strLog;
|
||
|
|
}
|
||
|
|
|
||
|
|
WriteLog3(LogFileName, strLog, 200, 10*1024*1024);
|
||
|
|
}
|
||
|
|
|
||
|
|
|