// =============================== // 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); } } //Main Log write function (all the overloaded versions end up calling this one) void LogManager::log(QString file, QStringList msgs, QDateTime time){ if(file.isEmpty()){ return; } else if(!file.startsWith("/")){ //relative path - put it in the main log dir if(WS_MODE){ file.prepend(LOGDIR+"/websocket/"); } else{ file.prepend(LOGDIR+"/restserver/"); } } //qDebug() << "Log to File:" << file << msgs; if(file.isEmpty()){ return; } QFile LOG(file); //if(!LOG.exists()){ system( QString("touch "+file).toLocal8Bit() ); } if( !LOG.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text) ){ qDebug() << " - Could not write to log:" << file; return; } //error writing to file QTextStream stream(&LOG); 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.removeAt(files.length()-1); } else{ break; } } } //Now load each file in order (oldest->newest) and filter out the necessary logs QStringList logs; for(int i=0; i