changeset 128:d77779789e76

Improve logging.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 23 Aug 2017 13:41:01 +0300
parents 7db32f6c1476
children f6685c2eb75d
files src/main.cpp
diffstat 1 files changed, 38 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- 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.