6 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
7 @author: Sudheer K. <scifi1947 at gmail.com>
8 @license: GNU General Public License
22 #include <QTextStream>
25 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
27 class LogUtility : public QObject
36 LogUtility(QObject *parent = 0) :
40 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
41 //For maemo fremantle or harmattan use a common path
42 QDir logDir = QDir(QDir().homePath() + "/.vicar");
43 if (!logDir.exists()){
44 if (QDir().mkpath(logDir.absolutePath())){
45 qDebug() << "Vicar: Log directory created successfully";
48 qDebug() << "Vicar: Error creating log directory";
51 strPath = logDir.absolutePath() + "/vicar.log";
53 strPath = "vicar.log";
55 logFile = new QFile(strPath,this);
57 if (!logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
58 qDebug() << "Vicar: Error opening logfile for writing at path " << strPath;
63 if (logFile->isOpen())
65 qDebug() << "Vicar: In LogUtility object destructor..";
69 void logMessage(QString strMessage) {
71 QString strTimeNow = QDateTime::currentDateTime().toString("dd-MMM-yyyy HH:mm:ss");
73 if (logFile->isOpen() && logFile->isWritable()) {
74 QTextStream logStream(logFile);
75 logStream << QString("[%1] - %2").arg(strTimeNow,strMessage) << endl;
76 qDebug() << QString("Vicar: [%1] - %2").arg(strTimeNow,strMessage);
79 qDebug() << "ERROROPENINGLOGFILE" << QString("Vicar: [%1] - %2").arg(strTimeNow,strMessage);
84 LogUtility(QString logPath,QObject *parent = 0) :
86 logFilePath = logPath;
93 void logMessage(QString strMessage, bool appendMode = true) {
95 QFile logFile(logFilePath);
100 success = logFile.open(QIODevice::Append | QIODevice::WriteOnly | QIODevice::Text);
103 success = logFile.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text);
106 QString strTimeNow = QDateTime::currentDateTime().toString("dd-MMM-yyyy HH:mm:ss");
108 QTextStream logStream(&logFile);
109 logStream << strTimeNow << " - " << strMessage << endl;
112 qDebug() << "ERROROPENINGLOGFILE" << " - " << strMessage;
118 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
121 #endif // LOGUTILITY_H