只有在程序出问题以后才会知道打一个好的日志有多么重要。该日志生成文件以年月日时命名的txt 存储。
//log.h 如下:
class Log
{
public:
static Log* instance;
static Log* GetInstance();
Log();
~Log();
bool WriteLog(CString strFilePath, CString str);
bool WriteLog(CString str);
CString GetModulePathString();
CString CharToHex(unsigned char *pBuf, int len);
bool ReadLog(CString strFileName, CString& retLog);
char* ReadLog(CString strFileName, int& nFileLen);
};
//log.cpp 如下:
#include "stdafx.h"
#include "Log.h"
#include <string>
using namespace std;
Log* Log::instance = NULL;
Log::Log()
{
}
Log* Log::GetInstance(){
if (instance == NULL){
instance = new Log();
}
return instance;
}
Log::~Log()
{
}
CString Log::GetModulePathString()
{
CString sPath;
GetModuleFileName(NULL, sPath.GetBufferSetLength(MAX_PATH + 1), MAX_