#include <iostream.h>
#include <afx.h>
#include <afxdisp.h>
char g_szLogFileName[20] ="d:\\abc.txt";
//typedef char* LPCTSTR;
void WriteLog(int nLevel,LPCTSTR lpszFormat,...)
{
if(nLevel<0)
return;
CString str;
switch(nLevel)
{
case 1:
str="More debugging";
break;
case 2:
str="Simple Debugging";
break;
case 3:
str="General Tips";
break;
case 4:
str="Important info";
break;
case 5:
str="Minor error";
break;
case 6:
str="General Error";
break;
case 7:
str="Serious Error";
break;
case 8:
str="Run info";
break;
default:
str="Tip info";
break;
}
CString szMsg;
va_list argList;
va_start(argList, lpszFormat);
szMsg.FormatV(lpszFormat, argList);
va_end(argList);
COleDateTime dt=COleDateTime::GetCurrentTime();
CString szInfo;
szInfo.Format("[%s]%s:%s\r\n",dt.Format("%Y-%m-%d %H:%M:%S"),str,szMsg);
CFile fe;
try
{
if(!fe.Open(g_szLogFileName,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite))
return;
fe.SeekToEnd();
fe.Write(szInfo.GetBuffer(0),szInfo.GetLength());
fe.Close();
}
catch(...)
{
}
}
int main()
{
WriteLog(1,"这是一个非常严重的错误");
cout<<"ok"<<endl;
// int j;
// cin>>j;
return 0;
}