#include "logout.h" #include "iostream" extern FILE *file=NULL; #define _DEBUG void (*pFunction)(QString message)= nullptr; QString colorcode = "\033["; QString lastdatestr=""; int outputlevel = 2; // //void logout(QString str) //{ //#ifdef _DEBUG // qDebug()<5) { if (pFunction!= nullptr) { pFunction(str); } } //return; if (level > outputlevel) { return; } //QTextCodec *codec = QTextCodec::codecForName("GBK");//�޸������� int colorint; switch (level) { case 0: { // return; break; } case 1: { qDebug() << "\033[32m";//��ɫ break; } case 2: { qDebug() << "\033[35m";//��ɫ break; } case 3: { qDebug() << "\033[31m";//��ɫ break; } case 5: { qDebug() << "\033[36m"; break; } default: { break; } } //str=codec->toUnicode(str.toStdString().c_str()); //qDebug() << str; //qDebug() << "\033[0m"; //std::cout<"; std::fflush(stdout); } void setoutlevel(int level /*= 4*/) { outputlevel = level; } void setfunc(void (*sendmassage1)(QString)) { pFunction=sendmassage1; } void writelogtofile(QString sender,QString qstr) { QDateTime currentTime = QDateTime::currentDateTime(); QString datestr=currentTime.toString("yyyy_MM_dd"); if (lastdatestr!=datestr) { if (file!=NULL) { fclose(file); file=NULL; } lastdatestr=datestr; } if (file==NULL) { QString path="/home/iris/log/"+currentTime.toString("yyyy_MM_dd")+".log"; system("mkdir -p /home/iris/log"); file=fopen(path.toStdString().c_str(),"a+"); fprintf(file,"\n\n\n\nstart---------------------------------------------------------------------------------\n"); } fprintf(file,"%s %s: %s\n",currentTime.toString("yyyy-MM-dd hh:mm:ss.zzz").toStdString().c_str(),sender.toStdString().c_str(),qstr.toStdString().c_str()); fflush(file); } void saveData(QString sender,QString qstr) { QDateTime currentTime = QDateTime::currentDateTime(); QString datestr=currentTime.toString("yyyy_MM_dd"); if (lastdatestr!=datestr) { if (file!=NULL) { fclose(file); file=NULL; } lastdatestr=datestr; } if (file==NULL) { QString path="/home/iris/TempData/"+currentTime.toString("yyyy_MM_dd")+".csv"; system("mkdir -p /home/iris/TempData"); file=fopen(path.toStdString().c_str(),"a+"); fprintf(file,QString::fromLocal8Bit("日期, 数据类型, 日期~n").toStdString().c_str()); } fprintf(file,"%s,%s,%s\n",currentTime.toString("yyyy-MM-dd hh:mm:ss.zzz").toStdString().c_str(),sender.toStdString().c_str(),qstr.toStdString().c_str()); fflush(file); }