Version 0.7-0
[vicar] / src / vicar-lib / cpp / logutility.h
diff --git a/src/vicar-lib/cpp/logutility.h b/src/vicar-lib/cpp/logutility.h
new file mode 100644 (file)
index 0000000..ebca69e
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+@version: 0.6
+@author: Sudheer K. <scifi1947 at gmail.com>
+@license: GNU General Public License
+*/
+
+#ifndef LOGUTILITY_H
+#define LOGUTILITY_H
+#include <QFile>
+#include <QIODevice>
+#include <QTextStream>
+#include <QDateTime>
+#include <QDebug>
+
+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