123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include "logthread.h"
- LogThread::LogThread(QObject *parent) :
- QThread(parent)
- {
- keep = false;
- dataList.clear();
- wrongList.clear();
- printf("logthread init\n");
- QDir dir("/usky/dmp/log");
- if(!dir.exists())
- system("mkdir -p /usky/dmp/log");
- file = new QFile("/usky/dmp/log/data-"+QDate::currentDate().toString("yyyyMMdd")+".log");
- day = QDate::currentDate().day();
- }
- void LogThread::appendData(QString data)
- {
- dataList.append(data);
- }
- void LogThread::stop()
- {
- keep = false;
- }
- void LogThread::run()
- {
- printf("dmp log thread start\n");
- if(file->open(QIODevice::ReadWrite|QIODevice::Append|QIODevice::Text)){
- file->write(QString("ytDMPDataServer start at %1.\r\n").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz")).toUtf8());
- file->close();
- }
- keep = true;
- while(keep){
- if(dataList.length()>0){
- if(day!=QDate::currentDate().day()){
- day = QDate::currentDate().day();
- file = new QFile("/usky/dmp/log/data-"+QDate::currentDate().toString("yyyyMMdd")+".log");
- }
- if(file->open(QIODevice::ReadWrite|QIODevice::Append|QIODevice::Text)){
- while(dataList.length()>0){
- file->write(dataList.first().toUtf8());
- file->write("\r\n");
- dataList.removeFirst();
- usleep(1000);
- }
- file->close();
- }
- }
- usleep(50000);
- }
- }
|