一次被驳回的没法看C++日志模块

来源:互联网 发布:淘宝直通车怎么进入 编辑:程序博客网 时间:2024/06/09 20:22
#include "LOG.h"LOG::LOG(string folderName){this->currentDate = getCurrentDate();//判断日志目录是否存在  if(_access(folderName.data(),0) != 0)_mkdir(folderName.c_str());folderName =folderName+"//"+currentDate;    if(_access(folderName.data(),0) != 0)_mkdir(folderName.c_str());this->folderName = folderName;        }LOG::~LOG(){}string LOG::getCurrentTime(){time_t t = time(0); char tmp[64];string strt;strftime( tmp, sizeof(tmp), "%H:%M:%S",localtime(&t) );strt = tmp;return strt;}void LOG::writeLog(string fileName,string info,string file,int liner){currentTime = getCurrentTime();this->filePath = folderName+"//"+fileName;this->m_outputFile = new fstream;      string strname;strname= filePath+".txt";const char* c_s = strname.c_str();    m_outputFile->open(c_s,ofstream::out|ofstream::app); //打开日志文件*m_outputFile<<"["<<currentTime<<"]:"<<info<<endl<<"\t@"<<file<<"---->line:"<<liner<<endl;delete m_outputFile; }string LOG::getLogInfo(){string str;str=" ";return str;}string LOG::getCurrentDate(){time_t t = time(0); char tmp[64];string strt;strftime( tmp, sizeof(tmp), "%Y-%m-%d",localtime(&t) );strt = tmp;return strt;}

test.c

#include "iostream"#include "LOG.h"using namespace std;int main(){LOG logg("log");logg.writeLog("socket","萨卡迪卡",__FILE__,__LINE__);return 0;}


0 0
原创粉丝点击