# HG changeset patch # User Matti Hamalainen # Date 1503484861 -10800 # Node ID d77779789e7667768aac4675cfc3c4c8163c7755 # Parent 7db32f6c1476a7d4a32780ea0ce7e4b2596944df Improve logging. diff -r 7db32f6c1476 -r d77779789e76 src/main.cpp --- a/src/main.cpp Wed Aug 23 13:22:36 2017 +0300 +++ b/src/main.cpp Wed Aug 23 13:41:01 2017 +0300 @@ -23,42 +23,6 @@ // -// Error logging -// -void slLog(QString msg) -{ - QString filename = qApp->applicationDirPath() + QDir::separator() + APP_LOG_FILE; - QFile fh(filename); - if (fh.open(QIODevice::WriteOnly | QIODevice::Append)) - { - QTextStream out(&fh); - out << msg << "\n"; - fh.close(); - } -} - - -// -// Display an error dialog with given title and message -// -int slErrorMsg(QString title, QString msg) -{ - QMessageBox dlg; - - slLog("ERROR: "+ msg); - - dlg.setText(title); - dlg.setInformativeText(msg); - dlg.setTextFormat(Qt::RichText); - dlg.setIcon(QMessageBox::Critical); - dlg.setStandardButtons(QMessageBox::Ok); - dlg.setDefaultButton(QMessageBox::Ok); - - return dlg.exec(); -} - - -// // Convert QString to a double value, replacing comma // double slMoneyStrToValue(const QString &str) @@ -109,6 +73,44 @@ // +// Error logging +// +void slLog(QString msg) +{ + QString filename = qApp->applicationDirPath() + QDir::separator() + APP_LOG_FILE; + QFile fh(filename); + if (fh.open(QIODevice::WriteOnly | QIODevice::Append)) + { + QTextStream out(&fh); + out << + slDateTimeToLocal(QDateTime::currentDateTimeUtc()).toString(QStringLiteral("yyyy-MM-dd hh:mm:ss")) + << " : " << msg << "\n"; + fh.close(); + } +} + + +// +// Display an error dialog with given title and message +// +int slErrorMsg(QString title, QString msg) +{ + QMessageBox dlg; + + slLog("ERROR: "+ msg); + + dlg.setText(title); + dlg.setInformativeText(msg); + dlg.setTextFormat(Qt::RichText); + dlg.setIcon(QMessageBox::Critical); + dlg.setStandardButtons(QMessageBox::Ok); + dlg.setDefaultButton(QMessageBox::Ok); + + return dlg.exec(); +} + + +// // Check if an SQL error has occured (for given QSqlError) and // report it to stdout if so. Return "false" if error has occured, // true otherwise.