Added a Log Parser & Atempt to fix #12
Added a class that pars all qDebug Messages to a log file. Atempt to fix #12, on linux it works.
This commit is contained in:
parent
99aa0ed909
commit
a6a923e31b
5 changed files with 85 additions and 22 deletions
|
@ -42,7 +42,8 @@ HEADERS += \
|
|||
src/jceData/Calendar/calendarSchedule.h \
|
||||
src/jceData/CSV/csv_exporter.h \
|
||||
src/appDatabase/simplecrypt.h \
|
||||
src/jceData/Calendar/calendardialog.h
|
||||
src/jceData/Calendar/calendardialog.h \
|
||||
src/jce_logger.h
|
||||
|
||||
SOURCES += \
|
||||
main/CalendarTab/CalendarManager.cpp \
|
||||
|
@ -62,6 +63,7 @@ SOURCES += \
|
|||
src/jceData/Calendar/calendarSchedule.cpp \
|
||||
src/jceData/CSV/csv_exporter.cpp \
|
||||
src/appDatabase/simplecrypt.cpp \
|
||||
src/jceData/Calendar/calendardialog.cpp
|
||||
src/jceData/Calendar/calendardialog.cpp \
|
||||
src/jce_logger.cpp
|
||||
|
||||
|
||||
|
|
|
@ -3,10 +3,13 @@
|
|||
#include <QTranslator>
|
||||
#include <QDebug>
|
||||
#include "../src/appDatabase/savedata.h"
|
||||
#include "../src/jce_logger.h"
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
qInstallMessageHandler(jce_logger::customMessageHandler);
|
||||
qDebug() << "Start : JCE Manager Launched" << Q_FUNC_INFO;
|
||||
QApplication a(argc, argv);
|
||||
QTranslator translator;
|
||||
QString loco;
|
||||
|
@ -16,13 +19,22 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
QString locale = QLocale::system().name();
|
||||
translator.load("jce_"+locale , a.applicationDirPath());
|
||||
}else if(loco == "he")
|
||||
qDebug() << "Local : Default Local Loaded";
|
||||
}else if(loco == "he"){
|
||||
translator.load("jce_he" , a.applicationDirPath());
|
||||
else
|
||||
qDebug() << "Local : Hebrew Local Loaded";
|
||||
}else{
|
||||
translator.load("jce_en" , a.applicationDirPath());
|
||||
qDebug() << "Local : English Local Loaded";
|
||||
}
|
||||
a.installTranslator(&translator);
|
||||
MainScreen w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
int returnCode = a.exec();
|
||||
if(returnCode == 0)
|
||||
qDebug() << "End : JCE Manager Ended Successfully With A Return Code: " << returnCode;
|
||||
else
|
||||
qCritical() << "End : JCE Manager Ended Unusccessfully With A Return Code: " << returnCode;
|
||||
return returnCode;
|
||||
}
|
||||
|
|
|
@ -8,21 +8,24 @@ CSV_Exporter::CSV_Exporter()
|
|||
bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *cal)
|
||||
{
|
||||
if ((cal == NULL) || (calSched == NULL) || (calSched->getCourses() == NULL)) //pointers checking!
|
||||
{
|
||||
qWarning() << "CSV : User trying to export to csv but no calendar was loaded. aborting.";
|
||||
return false;
|
||||
qDebug() << "Getting path for csv file from user...";
|
||||
}
|
||||
qDebug() << "CSV : Getting path for csv file from user...";
|
||||
QString filePath = getFileFath();
|
||||
if(filePath == NULL) //User canceled
|
||||
{
|
||||
qDebug() << "User pressed Cancel... returning false";
|
||||
qDebug() << "CSV : User pressed Cancel... returning false";
|
||||
return false;
|
||||
}
|
||||
qDebug() << "User Chose: " << filePath;
|
||||
qDebug() << "Atempting to export the Schedule...";
|
||||
qDebug() << "CSV : User Chose: " << filePath;
|
||||
qDebug() << "CSV : Atempting to export the Schedule...";
|
||||
|
||||
QFile file(filePath);
|
||||
if(!file.open(QIODevice::ReadWrite | QIODevice::Text |QIODevice::Truncate))
|
||||
if(!file.open(QIODevice::ReadWrite | QIODevice::Truncate))
|
||||
{
|
||||
qDebug() << "unable to open/create the file... maybe permissions error.";
|
||||
qCritical() << "CSV : unable to open/create the file... maybe permissions error.";
|
||||
return false;
|
||||
}//else
|
||||
//Delete the file
|
||||
|
@ -48,25 +51,17 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca
|
|||
for(;currentDate <= cal->getEndDate(); currentDate = currentDate.addDays(7))
|
||||
{
|
||||
QString line = makeLine(name, ¤tDate, startH, startM, endH, endM, lecturer, room, type);
|
||||
#ifdef Q_OS_LINUX || Q_OS_UNIX
|
||||
if(line != NULL)
|
||||
out << line << char(0x0A);
|
||||
#endif
|
||||
#ifdef Q_OS_OSX
|
||||
if(line != NULL)
|
||||
out << line << char(0x0A);
|
||||
#endif
|
||||
#ifdef Q_OS_WIN
|
||||
if(line != NULL)
|
||||
out << line << char(0x0D) << char(0x0A);
|
||||
#endif
|
||||
else
|
||||
qWarning() << "CSV : Got A NULL in Line! in function: " << Q_FUNC_INFO;
|
||||
}
|
||||
out.flush();
|
||||
}
|
||||
|
||||
|
||||
file.close();
|
||||
qDebug() << "Saved Successfuly! - HazZaA!";
|
||||
qDebug() << "CSV : Exported Successfully";
|
||||
return true;
|
||||
|
||||
}
|
||||
|
|
37
src/jce_logger.cpp
Normal file
37
src/jce_logger.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include "jce_logger.h"
|
||||
|
||||
/*
|
||||
* This Static method will help parsing our debug messages to a readable Log file
|
||||
*
|
||||
* timestamp - Message type - message
|
||||
*/
|
||||
void jce_logger::customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
|
||||
QString dt = QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss");
|
||||
QString txt = QString("%1\t").arg(dt);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case QtDebugMsg:
|
||||
txt += QString("DEBUG \t\t %1").arg(msg);
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
txt += QString("WARNING \t %1").arg(msg);
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
txt += QString("CRITICAL \t %1").arg(msg);
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
txt += QString("FATAL \t\t %1").arg(msg);
|
||||
abort();
|
||||
break;
|
||||
}
|
||||
|
||||
QFile outFile("J_M_Log.log");
|
||||
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
|
||||
|
||||
QTextStream textStream(&outFile);
|
||||
textStream << txt << endl;
|
||||
}
|
17
src/jce_logger.h
Normal file
17
src/jce_logger.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef JCE_LOGGER_H
|
||||
#define JCE_LOGGER_H
|
||||
|
||||
#include <QMessageLogContext>
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
class jce_logger
|
||||
{
|
||||
public:
|
||||
static void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
|
||||
|
||||
};
|
||||
|
||||
#endif // JCE_LOGGER_H
|
Loading…
Reference in a new issue