资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

c++日志接口等级

 头文件

成都创新互联公司是一家集网站建设,昭苏企业网站建设,昭苏品牌网站建设,网站定制,昭苏网站建设报价,网络营销,网络优化,昭苏网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

#pragma  once

#include

#include

#include

using namespace std;

#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,...);

原文件:

#include "stdafx.h"

#include "log.h"

long m_tracelevel = INFOR_LOG | ERROR_LOG | DEBUG_LOG | TRACE_LOG;

#define DATAMAXLEN 10240

#define FUNMAXLEN  256

void setTraceLevel(int type)

{

m_tracelevel = type;

m_tracelevel |= (INFOR_LOG | ERROR_LOG);

}

void SaveLog(char *funName, int returnValue, char *Msg)

{

char sFileName[FUNMAXLEN];

char sLog[DATAMAXLEN + FUNMAXLEN*2];

SYSTEMTIME CurTime;

GetLocalTime(&CurTime);  

_mkdir("D:\\driver");

char temp[MAX_PATH] = {};

sprintf(temp,"D:\\driver\\%04d%02d",CurTime.wYear,CurTime.wMonth);

_mkdir(temp);

sprintf(sFileName,"%s\\log%04d%02d%02d.txt",temp,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);

ofstream  f(sFileName,ios::out|ios::app);

if (f.good())

{

f<

f.close();

}

}

void log_data(char* fname,char* errmsg,char *errvalue)

{

char sFileName[FUNMAXLEN];

char sLog[DATAMAXLEN + FUNMAXLEN*2];

SYSTEMTIME CurTime;

GetLocalTime(&CurTime);  

_mkdir("D:\\driver");

char temp[MAX_PATH] = {};

sprintf(temp,"D:\\driver\\%04d%02d",CurTime.wYear,CurTime.wMonth);

_mkdir(temp);

sprintf(sFileName,"%s\\log%04d%02d%02d.txt",temp,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);

ofstream  f(sFileName,ios::out|ios::app);

if (f.good())

{

f<

f.close();

}

}

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);

}

}

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);

}

}

void log_debug(char* fname,char* errmsg,char *format,...)

{

if(m_tracelevel & DEBUG_LOG)

{

char tmpbuf[FUNMAXLEN];

char errvalue[DATAMAXLEN + FUNMAXLEN*2];

sprintf(tmpbuf,"debug 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);

}

}

void log_trace(char* fname,char* errmsg,char *format,...)

{

if(m_tracelevel & TRACE_LOG)

{

char tmpbuf[FUNMAXLEN];

char errvalue[DATAMAXLEN + FUNMAXLEN*2];

sprintf(tmpbuf,"trace 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);

}

}

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);

}


名称栏目:c++日志接口等级
文章地址:http://cdkjz.cn/article/jcdseg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220