65,187
社区成员




#ifndef BaseLog_H
#define BaseLog_H
#include<cstdio>
#include<string>
#include<process.h>
#include<stdarg.h>
using namespace std;
#define DEBUG printf("[File:%s,Line:%d,Fun:%s] \n",__FILE__,__LINE__,__FUNCTION__)
//#define TRACE printf
#define LOG SetLine(__LINE__),SetFile(__FILE__),log
char *mfilename;
int mline;
void SetLine(int num)
{
mline=num;
};
void SetFile(char *filenm)
{
mfilename=filenm;
};
void log(const char* traceMessage, ...)
{
char chSendbuf[1025] = {0};
memset(chSendbuf, 0, 1024);
va_list ap;
va_start(ap, traceMessage);
vsprintf(chSendbuf, traceMessage, ap);
va_end(ap);
string Sendbuf;
int iBufLen = strlen(chSendbuf);
while ( iBufLen > 0 )
{
if ( chSendbuf[iBufLen-1]== '\n' || chSendbuf[iBufLen-1] == '\r' )
{
--iBufLen ;
continue ;
}
else
{
Sendbuf = chSendbuf+iBufLen ;
chSendbuf[iBufLen] = 0 ;
break ;
}
}
if ( Sendbuf.length() == 0 ) Sendbuf = "\n" ;
char tmp[2048] = {0};
if(mline > 1)
{
// Date nowtime = Date::GetCurrentTime();
// nowtime.toString();
// sprintf(tmp,"[%d]%s %s%s",nowtime.toString().c_str(),GetFilelineNum(),getpid(),chSendbuf,Sendbuf.c_str());
sprintf(tmp,"(%d)[%s][Line:%d]%s %s",getpid(),mfilename,mline,chSendbuf,Sendbuf.c_str());
}
else if( mline == 1)
sprintf(tmp, "(%d)[%s][Line:%d]%s%s",getpid(),mfilename,mline,chSendbuf,Sendbuf.c_str());
else
sprintf(tmp, "(%d)[%s][Line:%d]%s%s",getpid(),mfilename,mline,chSendbuf,Sendbuf.c_str());
printf("%s\n",tmp);
};
#endif
#include"tt.h"
#include"add.h"
int main(int argc,char *argv[])
{
long a=10000;
LOG("%d",argc);
for(int i=0;i<argc;i++)
{
LOG("%s,%ld",argv[i],a);
}
LOG("end");
int x=100,y=200;
CAdd myadd;
myadd.add(x,y);
return 0;
}
#ifndef Add_H
#define Add_H
#include"tt.h"
class CAdd
{
public:
CAdd() ;
virtual ~CAdd() ;
static int add(int a,int b);
};
#endif
#include"add.h"
CAdd::CAdd()
{
}
CAdd::~CAdd()
{
}
int CAdd::add(int a,int b)
{
LOG("%d,%d,sum=%d",a,b,a+b);
return a+b;
}
#ifndef BaseLog_H
#define BaseLog_H
#include<cstdio>
#include<string>
#include<process.h>
#include<stdarg.h>
using namespace std;
#define DEBUG printf("[File:%s,Line:%d,Fun:%s] \n",__FILE__,__LINE__,__FUNCTION__)
#define LOG SetLine(__LINE__),SetFile(__FILE__),log
char *mfilename;
int mline;
inline void SetLine(int num)
{
mline=num;
};
inline void SetFile(char *filenm)
{
mfilename=filenm;
};
inline void log(const char* traceMessage, ...)
{
char chSendbuf[1025] = {0};
memset(chSendbuf, 0, 1024);
va_list ap;
va_start(ap, traceMessage);
vsprintf(chSendbuf, traceMessage, ap);
va_end(ap);
string Sendbuf;
int iBufLen = strlen(chSendbuf);
while ( iBufLen > 0 )
{
if ( chSendbuf[iBufLen-1]== '\n' || chSendbuf[iBufLen-1] == '\r' )
{
--iBufLen ;
continue ;
}
else
{
Sendbuf = chSendbuf+iBufLen ;
chSendbuf[iBufLen] = 0 ;
break ;
}
}
if ( Sendbuf.length() == 0 ) Sendbuf = "\n" ;
char tmp[2048] = {0};
if(mline > 1)
{
// Date nowtime = Date::GetCurrentTime();
// nowtime.toString();
// sprintf(tmp,"[%d]%s %s%s",nowtime.toString().c_str(),GetFilelineNum(),getpid(),chSendbuf,Sendbuf.c_str());
sprintf(tmp,"(%d)[%s][Line:%d]%s %s",getpid(),mfilename,mline,chSendbuf,Sendbuf.c_str());
}
else if( mline == 1)
sprintf(tmp, "(%d)[%s][Line:%d]%s%s",getpid(),mfilename,mline,chSendbuf,Sendbuf.c_str());
else
sprintf(tmp, "(%d)[%s][Line:%d]%s%s",getpid(),mfilename,mline,chSendbuf,Sendbuf.c_str());
printf("%s\n",tmp);
};
#endif
//add.cpp
#include"add.h"
CAdd::CAdd()
{
}
CAdd::~CAdd()
{
}
int CAdd::add(int a,int b)
{
LOG("%d,%d,sum=%d",a,b,a+b);
return a+b;
}
(3512)[f:\ct8\csdn\tt.cpp][Line:9]1
(3512)[f:\ct8\csdn\tt.cpp][Line:12]F:\CT8\ads\Debug\ads.exe,10000
(3512)[f:\ct8\csdn\tt.cpp][Line:14]end
(3512)[f:\ct8\csdn\add.cpp][Line:14]100,200,sum=300
Press any key to continue
//tt.h
#ifndef BaseLog_H
#define BaseLog_H
#include<cstdio>
#include<string>
#include<process.h>
#include<stdarg.h>
using namespace std;
#define DEBUG printf("[File:%s,Line:%d,Fun:%s] \n",__FILE__,__LINE__,__FUNCTION__)
//#define TRACE printf
#define LOG SetLine(__LINE__),SetFile(__FILE__),log
extern char *mfilename;
extern int mline;
void SetLine(int num);
void SetFile(char *filenm);
void log(const char* traceMessage, ...);
#endif
//tt.cpp
#include"tt.h"
#include"add.h"
int main(int argc,char *argv[])
{
long a=10000;
LOG("%d",argc);
for(int i=0;i<argc;i++)
{
LOG("%s,%ld",argv[i],a);
}
LOG("end");
int x=100,y=200;
CAdd myadd;
myadd.add(x,y);
return 0;
}
char *mfilename;
int mline;
void SetLine(int num)
{
mline=num;
};
void SetFile(char *filenm)
{
mfilename=filenm;
};
void log(const char* traceMessage, ...)
{
char chSendbuf[1025] = {0};
memset(chSendbuf, 0, 1024);
va_list ap;
va_start(ap, traceMessage);
vsprintf(chSendbuf, traceMessage, ap);
va_end(ap);
string Sendbuf;
int iBufLen = strlen(chSendbuf);
while ( iBufLen > 0 )
{
if ( chSendbuf[iBufLen-1]== '\n' || chSendbuf[iBufLen-1] == '\r' )
{
--iBufLen ;
continue ;
}
else
{
Sendbuf = chSendbuf+iBufLen ;
chSendbuf[iBufLen] = 0 ;
break ;
}
}
if ( Sendbuf.length() == 0 ) Sendbuf = "\n" ;
char tmp[2048] = {0};
if(mline > 1)
{
// Date nowtime = Date::GetCurrentTime();
// nowtime.toString();
// sprintf(tmp,"[%d]%s %s%s",nowtime.toString().c_str(),GetFilelineNum(),getpid(),chSendbuf,Sendbuf.c_str());
sprintf(tmp,"(%d)[%s][Line:%d]%s %s",getpid(),mfilename,mline,chSendbuf,Sendbuf.c_str());
}
else if( mline == 1)
sprintf(tmp, "(%d)[%s][Line:%d]%s%s",getpid(),mfilename,mline,chSendbuf,Sendbuf.c_str());
else
sprintf(tmp, "(%d)[%s][Line:%d]%s%s",getpid(),mfilename,mline,chSendbuf,Sendbuf.c_str());
printf("%s\n",tmp);
};
//add.h
#ifndef Add_H
#define Add_H
#include"tt.h"
class CAdd
{
public:
CAdd() ;
virtual ~CAdd() ;
static int add(int a,int b);
};
#endif
//add.cpp
#include"add.h"
CAdd::CAdd()
{
}
CAdd::~CAdd()
{
}
int CAdd::add(int a,int b)
{
// LOG("%d,%d,sum=%d",a,b,a+b);
return a+b;
}