91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 2KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-21
  • 語言: C/C++
  • 標簽: 日志??MFC??

資源簡介

用于MFC程序日志記錄類,方面錯誤的查找

資源截圖

代碼片段和文件信息

#include?“StdAfx.h“
#include?“Log.h“


#define?LOG_EVENT?_T(“Global\\ChyLogWrite“)??
CString?CLog::s_strLogFile?=?_T(““);??
CString?CLog::s_strLogPrefix?=?_T(““);
CString?CLog::s_errorInfo=_T(““);
HANDLE?CLog::s_hWriteEvent?=?NULL;??

CLog::CLog(void)
{

}


CLog::~CLog(void)
{
}

//設置路徑和名稱分為兩種模式
//如果給出的不是絕對路徑:在EXE所在的目錄下,新建一個LOG文件夾,log文件夾下日志文件名稱為SMMS2014-10-28.log
//如果給出的是絕對路徑:則以絕對路徑為準。
short?CLog::SetLogFile(LPCTSTR?strPath)
{
//如果給的路徑為空,則設置為xxx.log目錄為EXE同目錄
if?(strPath==NULL)
{
//?得到當前的文件名
CString?strFileName;
GetModuleFileName(AfxGetInstanceHandle()strFileName.GetBuffer(_MAX_PATH)_MAX_PATH);
strFileName.ReleaseBuffer();

//?得到當前目錄
strFileName.Replace(“.exe““.log“);
s_strLogFile=strFileName;
}
else
{
s_strLogFile.Format(_T(“%s.log“)strPath);
}?
return?1;
}

short?CLog::SetPrefix(LPCTSTR?strPrefix)
{
if(strPrefix?&&?strPrefix[0])
{
s_strLogPrefix?=?strPrefix;
}
return?1;
}

//清空當前的文件,新建
void?CLog::CreateNewFile()
{
//-打開關閉文件-
if(s_strLogFile.IsEmpty())
SetLogFile(NULL);
CStdioFile?file;
if(!file.Open(s_strLogFile?CFile::modeCreate))
{
CString?str;
str.Format(_T(“打開文件失敗!路徑為:%s“)s_strLogFile);
AfxMessageBox(str);
exit(0);
}
file.Close();
}

short?CLog::GetDugInfo(LPCSTR?pDugInfo/*?=NULL?*/)
{
// char?file[16];??
//// char?func[16];??
// int?line;???
// sprintf(file__FILE__);?//文件名??
//// sprintf(func__FUNCTION__);//函數名????
// line=__LINE__; //行號

s_errorInfo.Format(_T(“%s“)pDugInfo);

return?1;
}

short?CLog::WriteMsg(LPCTSTR?strFormat)
{
//--
if(s_hWriteEvent==NULL)
{
s_hWriteEvent?=?OpenEvent(0?FALSELOG_EVENT);
if(s_hWriteEvent==NULL)
s_hWriteEvent?=?CreateEvent(NULL?FALSE?TRUE?LOG_EVENT);?
}
WaitForSingleobject(s_hWriteEvent?INFINITE);
//-打開關閉文件-
if(s_strLogFile.IsEmpty())
SetLogFile(NULL);
CStdioFile?file;
if(file.Open(s_strLogFile?CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite))
{
file.SeekToEnd();

CString???strPart_Time;
{
SYSTEMTIME?sysTime??=?{0};
GetLocalTime(&sysTime);
strPart_Time.Format(_T(“\n%2d-%2d-%2d?%2d:%2d:%2d“)??
sysTime.wYearsysTime.wMonthsysTime.wDaysysTime.wHour?sysTime.wMinute?sysTime.wSecond);?
}
CString??str;

str=strPart_Time+_T(“\t“)+s_errorInfo;
file.WriteString(str);
s_errorInfo=““;

str=_T(“\n[“)+s_strLogPrefix+_T(“]“)+strFormat+_T(“\n“);
file.WriteString(str);
file.Close();
}
SetEvent(s_hWriteEvent);
return?1;
}





?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????2704??2014-12-30?14:50??Log.cpp

?????文件????????726??2014-12-30?14:41??Log.h

-----------?---------??----------?-----??----

?????????????????3430????????????????????2


評論

共有 條評論