頭文件
成都創(chuàng)新互聯(lián)公司:2013年至今為各行業(yè)開拓出企業(yè)自己的“網(wǎng)站建設(shè)”服務(wù),為近千家公司企業(yè)提供了專業(yè)的網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)和網(wǎng)站推廣服務(wù), 按需網(wǎng)站制作由設(shè)計(jì)師親自精心設(shè)計(jì),設(shè)計(jì)的效果完全按照客戶的要求,并適當(dāng)?shù)奶岢龊侠淼慕ㄗh,擁有的視覺效果,策劃師分析客戶的同行競爭對手,根據(jù)客戶的實(shí)際情況給出合理的網(wǎng)站構(gòu)架,制作客戶同行業(yè)具有領(lǐng)先地位的。#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); } 另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
本文名稱:c++日志接口等級-創(chuàng)新互聯(lián)
URL標(biāo)題:http://weahome.cn/article/ijecj.html