// =============================== // PC-BSD REST/JSON API Server // Available under the 3-clause BSD License // Written by: Ken Moore 2016 // ================================= #include "LogManager.h" #include "globals.h" #define TMPBREAK "" //Overall check/creation of the log directory void LogManager::checkLogDir(){ //Determing the log dir based on type of server QString logd = LOGDIR; //base log dir if(WS_MODE){ logd.append("/websocket"); } else{ logd.append("/restserver"); } //Check/create the dir if(!QFile::exists(logd)){ QDir dir(logd); dir.mkpath(logd); } int daysold = CONFIG->value("prune_log_days_old",90).toInt(); //90 days by default if(daysold>0){ LogManager::pruneLogs(QDate::currentDate().addDays(0-daysold)); } } //Manual prune of logs older than designated date void LogManager::pruneLogs(QDate olderthan){ QString logd = LOGDIR; //base log dir if(WS_MODE){ logd.append("/websocket"); } else{ logd.append("/restserver"); } QDir dir(logd); QStringList files = dir.entryList(QStringList() << "*.log", QDir::Files, QDir::Name); //qDebug() << " - Got files:" << files << "Filter:" << tmp; for(int i=0; i QDateTime::fromString( all.first().section("]",0,0).section("[",1,1), Qt::ISODate) ){ break; }else{ all.removeAt(all.length()-1); } } // - now double check that none of the temporary line break replacements get through for(int i=0; i0 && files.last()!=tmp ){ files.removeAt(files.length()-1); } else{ break; } } //qDebug() << " - After filter:" << files; } //Now load each file in order (oldest->newest) and filter out the necessary logs QStringList logs; for(int i=0; i