?? log.cpp
字號:
#include "StdAfx.h"
#include ".\log.h"
#include "time.h"
#define Log LOG::Error
//int const ERROR=1;
//int const PACKET=2;
void LOG::GetCurTimeLocal(char *datestr)
{
SYSTEMTIME tim;
GetLocalTime(&tim);
sprintf(datestr,"--%02d/%02d %02d:%02d:%02d:%03d",tim.wMonth ,tim.wDay ,tim.wHour , tim.wMinute ,tim.wSecond,tim.wMilliseconds );
}
FILE * LOG::OpenFileByDate(int const iType)
{
char cpLogFile[128]={0};
FILE* fp=NULL;
time_t i=0;
tm *tim=NULL;
time(&i);
tim=localtime(&i);
char szFilePath[260] ={0} ;
std::string sPath;
GetModuleFileName(NULL,szFilePath,MAX_PATH);
int nPos;
sPath = szFilePath;
nPos=sPath.rfind ('\\');
sPath=sPath.substr(0,nPos);
if(iType==1)
{
sprintf(cpLogFile,"%s\\WLog%4d-%2d-%2d.log",sPath.c_str() ,tim->tm_year+1900,tim->tm_mon+1,tim->tm_mday);
}
else
{
sprintf(cpLogFile,"%s\\WLog%4d-%2d-%2d.log",sPath.c_str() ,tim->tm_year+1900,tim->tm_mon+1,tim->tm_mday);
}
fp=fopen(cpLogFile,"at");
return fp!=NULL?fp:NULL;
}
void LOG::Error(const char *fmt, ...)
{
FILE *fp=LOG::OpenFileByDate(1);
char buf[4096]={0};
char szTime[128]={0};
va_list args;
va_start(args, fmt);
GetCurTimeLocal(szTime);
snprintf(buf, sizeof(buf), "%s|%s\n",szTime, fmt);
vfprintf(fp, buf, args);
fflush(fp);
va_end(args);
fclose(fp);
}
void LOG::Packet(const char *fmt,...)
{
FILE *fp=LOG::OpenFileByDate(2);
char buf[4096]={0};
char szTime[128]={0};
va_list args;
va_start(args, fmt);
GetCurTimeLocal(szTime);
snprintf(buf, sizeof(buf), "%s|%s\n",szTime, fmt);
vfprintf(fp, buf, args);
fflush(fp);
va_end(args);
fclose(fp);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -