X-Git-Url: http://git.maemo.org/git/?p=vicar;a=blobdiff_plain;f=src%2Fvicar-lib%2Fcpp%2Flogutility.h;fp=src%2Fvicar-lib%2Fcpp%2Flogutility.h;h=ebca69e5c876fc156bc3cf6ccaac94566d4c8c67;hp=0000000000000000000000000000000000000000;hb=38440679f13b8dc528a9aff93cbf4935011fdb22;hpb=89f0017e6a73945ea83247472a6fa07d6ee536b5 diff --git a/src/vicar-lib/cpp/logutility.h b/src/vicar-lib/cpp/logutility.h new file mode 100644 index 0000000..ebca69e --- /dev/null +++ b/src/vicar-lib/cpp/logutility.h @@ -0,0 +1,56 @@ +/* +@version: 0.6 +@author: Sudheer K. +@license: GNU General Public License +*/ + +#ifndef LOGUTILITY_H +#define LOGUTILITY_H +#include +#include +#include +#include +#include + +class LogUtility : public QObject +{ + Q_OBJECT + +public: + LogUtility(QString logPath,QObject *parent = 0) : + QObject(parent){ + logFilePath = logPath; + } + + ~LogUtility(){ + } + +public slots: + void logMessage(QString strMessage, bool appendMode = true) { + + QFile logFile(logFilePath); + + bool success = false; + + if (appendMode){ + success = logFile.open(QIODevice::Append | QIODevice::WriteOnly | QIODevice::Text); + } + else{ + success = logFile.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text); + } + + QString strTimeNow = QDateTime::currentDateTime().toString("dd-MMM-yyyy HH:mm:ss"); + if (success) { + QTextStream logStream(&logFile); + logStream << strTimeNow << " - " << strMessage << endl; + } + else{ + qDebug() << "ERROROPENINGLOGFILE" << " - " << strMessage; + } + } + +private: + QString logFilePath; +}; + +#endif // LOGUTILITY_H