Initial Release
[marketstoday] / src / cpp / logutility.h
1 /*
2 @version: 0.1
3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
5 */
6
7 #ifndef LOGUTILITY_H
8 #define LOGUTILITY_H
9 #include <QDebug>
10 #include <QFile>
11 #include <QIODevice>
12 #include <QDateTime>
13
14 class LogUtility : public QObject
15 {
16     Q_OBJECT
17
18 public:
19     LogUtility(QObject *parent = 0) :
20         QObject(parent){
21
22     }
23     ~LogUtility(){
24         qDebug() << "Markets Today: In LogUtility object destructor..";
25     }
26
27 public slots:
28     void logMessage(QString strMessage) {
29
30         QString strTimeNow = QDateTime::currentDateTime().toString("dd-MMM-yyyy HH:mm:ss");
31         qDebug() << QString("Markets Today: [%1] - %2").arg(strTimeNow,strMessage);
32
33 #ifdef Q_WS_MAEMO_5
34     //For maemo use a common path
35         QFile logFile("/home/user/.marketstoday/marketstoday.log");
36 #else
37         QFile logFile("marketstoday.log");
38 #endif
39
40         if (!logFile.open(QIODevice::Append | QIODevice::WriteOnly | QIODevice::Text)) { return; }
41
42         QTextStream logStream(&logFile);
43         logStream <<  QString("Markets Today: [%1] - %2").arg(strTimeNow,strMessage) << endl;
44     }
45 };
46
47 #endif // LOGUTILITY_H
48 ;