91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 3KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2021-06-06
  • 語言: C/C++
  • 標(biāo)簽: c++??日志??單例??

資源簡介

c++實(shí)現(xiàn)的日志類,能夠按天寫日志,并且超過一定大小進(jìn)行備份,線程安全。

資源截圖

代碼片段和文件信息

#include?“StdAfx.h“
#include?“Logger.h“
#include?
#include?
#include?

using?namespace?HUALOG;
void?Logger::writeLog(LOG_LEVEL?level?std::string?msgstd::string?filename?int?line)
{??
CResGuard::CGuard?gd(_logrs);

std::string??fn=?GetFileName(level);
time_t?t;
time(&t);
struct?tm?tp;
localtime_s(&tp&t);
char?now_str[100]={0};
strftime(now_str?100?“%Y-%m-%d?%H:%M:%S“?&tp);


errno_t?rt?=?fopen_s(&_fofn.c_str()?“a“);
if?(rt?!=?0)?{
if(_fo)
fclose(_fo);
return;
}

fprintf_s(_fo?“%s?%s[%d]?:%s\r\n“now_strfilename.c_str()line?msg.c_str());
printf_s(“%s?%s[%d]?:%s\r\n“now_strfilename.c_str()line?msg.c_str());
fseek(_fo0SEEK_END);
long?position?=?ftell(_fo);
fclose(_fo);
if(position>_maxFileSize)
{
Rollover(fn);
}
}

std::string?Logger::GetFileName(LOG_LEVEL?level)
{
time_t?t;
time(&t);
struct?tm?tp;
localtime_s(&tp&t);
char?now_str[100]={0};
strftime(now_str?100??“%Y%m%d“?&tp);
std::string?fn(now_str);

if(_date==““)
{
_date?=fn;
_curIndex=0;
}
else?if(_date!=fn)
{
_date?=fn;
_curIndex=0;
}

fn.append(“_“);
switch?(level)
{
case?INFO_LOG:
fn+=“info.log“;
break;
case?DEBUG_LOG:
fn+=“debug.log“;
break;
case?WARNING_LOG:
fn+=“waring.log“;
break;
case?ERROR_LOG:
fn+=“error.log“;
break;
}
if(_path!=““)
fn?=_path+“\\“+fn;
return?fn;
}

void?Logger::Rollover(std::string&?filename)
{
RolloverFiles(filename);
std::ostringstream?source_oss;
std::ostringstream?target_oss;

source_oss.str(““);
target_oss.str(““);

source_oss?< target_oss?<
std::string?const?source?(source_oss.str?());
std::string?const?target?(target_oss.str?());
std::remove?(target.c_str());
std::rename(source.c_str()?target.c_str());
}

void?Logger::RolloverFiles(std::string&?filename)
{
std::ostringstream?buffer;
long?ret?;
if(_curIndex?==?_maxBackupIndex)
{

buffer< ret?=?std::remove(buffer.str().c_str());
}
std::ostringstream?source_oss;
std::ostringstream?target_oss;

for?(int?i?=?_curIndex;?i?>=?1;?--i)
{
source_oss.str(““);
target_oss.str(““);

source_oss?< target_oss?<
std::string?const?source?(source_oss.str?());
std::string?const?target?(target_oss.str?());


ret?=std::remove?(target.c_str());
std::rename(source.c_str()?target.c_str());
}

if(_curIndex!=(_maxBackupIndex-1))
_curIndex++;

}

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----

?????文件???????1715??2011-10-27?11:16??Singleton.h

?????文件???????2613??2011-10-28?09:38??Logger.cpp

?????文件???????3251??2011-10-28?09:47??Logger.h

-----------?---------??----------?-----??----

?????????????????7579????????????????????3


評(píng)論

共有 條評(píng)論