标签:c++ log 日志体系
你是否为代码没有注释而苦恼,你是否为BUG没有日志而伤心,是否无缘升职加薪,是否测试部的小妹妹周末陪了美工.....
4.请在.h头文件领取新手礼物
#define FATAL_LOG 0x0000
#define ERROR_LOG 0x0001
#define TRACE_LOG 0x0010
#define INFOR_LOG 0x0100
#define DEBUG_LOG 0x1000
#define MAX_NAME (256)
#define LOGSYNCTIME (1000)
void SaveLog(char *funName, int returnValue, char *Msg);
void setTraceLevel(int type);
void log_data(char* fname,char* errmsg,char *errvalue);
void log_fatal(char* fname,char* errmsg,char * format,...);
void log_error(char* fname,char* errmsg,char * format,...);
void log_infor(char* fname,char* errmsg,char * format,...);
void log_trace(char* fname,char* errmsg,char * format,...);
void log_debug(char* fname,char* errmsg,char * format,...);
3..cpp 配置天赋符文
long m_tracelevel = INFOR_LOG | ERROR_LOG;
#define DATAMAXLEN 10240
#define FUNMAXLEN 256
2.技能天赋介绍
----很好,现在请点击1级技能加点
被动技能: 程序猿可投出infor,error,debug,trace4种香蕉造成成吨伤害,等效于1斤狗粮
void setTraceLevel(int type)
{
m_tracelevel = type;
m_tracelevel |= (INFOR_LOG | ERROR_LOG);
}
D技能:吸收函数名,函数返回值,伤害来源数据 并回馈到本地.\driver\log年月日.txt
void SaveLog(char *funName, int returnValue, char *Msg)
{
char sFileName[FUNMAXLEN];
char sLog[DATAMAXLEN + FUNMAXLEN*2];
SYSTEMTIME CurTime;
GetLocalTime(&CurTime);
_mkdir(".\\driver");
sprintf(sFileName,".\\driver\\log%04d%02d%02d.txt",CurTime.wYear,CurTime.wMonth,CurTime.wDay,CurTime.wHour);
sprintf(sLog,"[%4d-%02d-%02d %02d:%02d:%02d:%003d][funName:%s][ret:%d][msg:%s]",
CurTime.wYear,CurTime.wMonth,CurTime.wDay,CurTime.wHour,CurTime.wMinute,CurTime.wSecond,CurTime.wMilliseconds,funName,returnValue,Msg);
fstream f;
f.open(sFileName, ios::app);
if(f.good())
{
f<<sLog<<endl;
f.close();
}
}
F技能:吸收函数名fname,敌方英雄文件名errmsg,伤害数据errvalue对本地.\driver\log年月日.txt造成成吨的文字伤害
void log_data(char* fname,char* errmsg,char *errvalue)
{
char sFileName[FUNMAXLEN];
char sLog[DATAMAXLEN + FUNMAXLEN*2];
SYSTEMTIME CurTime;
GetLocalTime(&CurTime);
_mkdir(".\\driver");
sprintf(sFileName,".\\driver\\log%04d%02d%02d.txt",CurTime.wYear,CurTime.wMonth,CurTime.wDay,CurTime.wHour);
sprintf(sLog,"[%4d-%02d-%02d %02d:%02d:%02d:%003d][%s][%s][%s]",
CurTime.wYear,CurTime.wMonth,CurTime.wDay,CurTime.wHour,CurTime.wMinute,CurTime.wSecond,CurTime.wMilliseconds,fname,errmsg,errvalue);
fstream f;
f.open(sFileName, ios::app);
if(f.good())
{
f<<sLog<<endl;
f.close();
}
}
Q技能:仍出infor香蕉在函数入参和出参造成伤害
吸收函数名fname,敌方英雄文件名errmsg,伤害数据字符串格式format
void log_infor(char* fname,char* errmsg,char *format,...)
{
if(m_tracelevel & INFOR_LOG)
{
char tmpbuf[FUNMAXLEN];
char errvalue[DATAMAXLEN + FUNMAXLEN*2];
sprintf(tmpbuf,"infor in %s",fname);
memset(errvalue,0x0,sizeof(errvalue));
va_list ap;
va_start(ap,format);
_vsnprintf(errvalue,DATAMAXLEN - 1,format,ap);
va_end(ap);
log_data(tmpbuf,errmsg,errvalue);
}
}
W技能:仍出error香蕉在函数有断言式错误提醒对方,我方已挂机
吸收函数名fname,敌方英雄文件名errmsg,伤害数据字符串格式format
void log_error(char* fname,char* errmsg,char *format,...)
{
if(m_tracelevel & ERROR_LOG)
{
char tmpbuf[FUNMAXLEN];
char errvalue[DATAMAXLEN + FUNMAXLEN*2];
sprintf(tmpbuf,"error in %s",fname);
memset(errvalue,0x0,sizeof(errvalue));
va_list ap;
va_start(ap,format);
_vsnprintf(errvalue,DATAMAXLEN - 1,format,ap);
va_end(ap);
log_data(tmpbuf,errmsg,errvalue);
}
}
E技能:仍出debug香蕉在函数在需要调试的地方,标记敌方英雄
吸收函数名fname,敌方英雄文件名errmsg,伤害数据字符串格式format
void log_debug(char* fname,char* errmsg,char *format,...)
{
if(m_tracelevel & ERROR_LOG)
{
char tmpbuf[FUNMAXLEN];
char errvalue[DATAMAXLEN + FUNMAXLEN*2];
sprintf(tmpbuf,"error in %s",fname);
memset(errvalue,0x0,sizeof(errvalue));
va_list ap;
va_start(ap,format);
_vsnprintf(errvalue,DATAMAXLEN - 1,format,ap);
va_end(ap);
log_data(tmpbuf,errmsg,errvalue);
}
}
R技能:仍出trace香蕉在函数在需要调试的地方,提醒打野,中miss,上miss,下miss,打野gank
吸收函数名fname,敌方英雄文件名errmsg,伤害数据字符串格式format
void log_trace(char* fname,char* errmsg,char *format,...)
{
if(m_tracelevel & ERROR_LOG)
{
char tmpbuf[FUNMAXLEN];
char errvalue[DATAMAXLEN + FUNMAXLEN*2];
sprintf(tmpbuf,"error in %s",fname);
memset(errvalue,0x0,sizeof(errvalue));
va_list ap;
va_start(ap,format);
_vsnprintf(errvalue,DATAMAXLEN - 1,format,ap);
va_end(ap);
log_data(tmpbuf,errmsg,errvalue);
}
}
(小键盘1)嗑药fatal,一直没用过就是懒不想删。点燃磕个药闭眼等回家.....
void log_fatal(char* fname,char* errmsg,char *format,...)
{
char tmpbuf[FUNMAXLEN];
char errvalue[DATAMAXLEN + FUNMAXLEN*2];
sprintf(tmpbuf,"fatal error in %s",fname);
memset(errvalue,0x0,sizeof(errvalue));
va_list ap;
va_start(ap,format);
_vsnprintf(errvalue,DATAMAXLEN - 1,format,ap);
va_end(ap);
log_data(tmpbuf,errmsg,errvalue);
}
---------------------------------------------------------------------------------------
本文出自 “诗意生活” 博客,请务必保留此出处http://whish.blog.51cto.com/10679902/1911758
标签:c++ log 日志体系
原文地址:http://whish.blog.51cto.com/10679902/1911758