Make use of new logging handler.

Sun, 05 Jun 2022 21:10:06 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 05 Jun 2022 21:10:06 +0200
changeset 256
c136bd15b084
parent 255
f237db73d4c8
child 257
cfba041bdaee

Make use of new logging handler.

src/database/database.cpp file | annotate | diff | comparison | revisions
src/database/db_product.cpp file | annotate | diff | comparison | revisions
src/database/db_recipe.cpp file | annotate | diff | comparison | revisions
--- a/src/database/database.cpp	Sun Jun 05 20:54:58 2022 +0200
+++ b/src/database/database.cpp	Sun Jun 05 21:10:06 2022 +0200
@@ -17,16 +17,10 @@
 #include "database.h"
 
 
-DataBase::DataBase(QObject *parent) : QObject(parent)
-{
-     
-}
+DataBase::DataBase(QObject *parent) : QObject(parent) {}
 
 
-DataBase::~DataBase()
-{
-
-}
+DataBase::~DataBase() {}
 
 
 bool DataBase::openDataBase(bool develop)
@@ -45,20 +39,20 @@
     db.setDatabaseName(settings.value("name").toString());
     db.setUserName(settings.value("user").toString());
     db.setPassword(settings.value("pass").toString());
-    settings.endGroup();
 
     if (db.open()) {
-	qDebug() << "Database open success";
+	qInfo() << "Database" << settings.value("name").toString() << "open success";
+	settings.endGroup();
 	return true;
-    } else {
-	qDebug() << "Database open failed";
-	return false;
     }
+
+    qWarning() << "Database open failed" << settings.value("host").toString() << settings.value("port").toString() << settings.value("name").toString() << settings.value("user").toString();
+    settings.endGroup();
+    return false;
 }
 
 void DataBase::closeDataBase()
 {
-    qDebug() << "Database close called";
     db.close();
 }
 
--- a/src/database/db_product.cpp	Sun Jun 05 20:54:58 2022 +0200
+++ b/src/database/db_product.cpp	Sun Jun 05 21:10:06 2022 +0200
@@ -27,7 +27,7 @@
     query.bindValue(":recno", recno);
     query.exec();
     if (! query.first()) {
-	qDebug() << "loadProduct seek error record" << recno;
+	qWarning() << "loadProduct seek error record" << recno;
 	QMessageBox::warning(dialog, QObject::tr("Database error"), QObject::tr("MySQL error: record %1 not found").arg(recno));
 	dialog->done(QDialog::Rejected);	// At this stage, this doesn't work because the dialog is not yet visible.
 	return false;
@@ -271,12 +271,11 @@
             const auto& formattedJson = QString("%1").arg(f_json);
             QJsonDocument fermentables = QJsonDocument::fromJson(formattedJson.toUtf8(),  &parseError);
             if (parseError.error != QJsonParseError::NoError) {
-                qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
+                qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
 	    } else if (fermentables.isArray()) {
 		double percentcheck = 0;
 		for (int i = 0; i < fermentables.array().size(); i++) {
 		    QJsonObject obj = fermentables.array().at(i).toObject();
-		    //qDebug() << i << obj;
 		    Fermentables f;
 		    f.f_inventory = 0;
 		    f.f_avail = false;
@@ -329,7 +328,7 @@
 			if (prod->fermentables.at(i).f_added < 4)
 			    prod->fermentables[i].f_percentage = round((prod->fermentables.at(i).f_amount / total) * 10000.0) / 100.0;
 		    }
-		    qDebug() << " fixed missing percentages";
+		    qInfo() << " fixed missing percentages";
 //		    is_changed();
 		}
 	}
@@ -342,11 +341,10 @@
             const auto& formattedJson = QString("%1").arg(h_json);
             QJsonDocument hops = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
             if (parseError.error != QJsonParseError::NoError) {
-                qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset;
+                qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset;
 	    } else if (hops.isArray()) {
 		for (int i = 0; i < hops.array().size(); i++) {
 		    QJsonObject obj = hops.array().at(i).toObject();
-		    //qDebug() << i << obj;
 		    Hops h;
 		    h.h_avail = false;
 		    h.h_inventory = 0;
@@ -388,11 +386,10 @@
             const auto& formattedJson = QString("%1").arg(m_json);
             QJsonDocument miscs = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
             if (parseError.error != QJsonParseError::NoError) {
-                qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset;
+                qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset;
 	    } else if (miscs.isArray()) {
 		for (int i = 0; i < miscs.array().size(); i++) {
 		    QJsonObject obj = miscs.array().at(i).toObject();
-		    //qDebug() << i << obj;
 		    Miscs m;
 		    m.m_avail = false;
 		    m.m_inventory = 0;
@@ -424,11 +421,10 @@
             const auto& formattedJson = QString("%1").arg(y_json);
             QJsonDocument yeasts = QJsonDocument::fromJson(formattedJson.toUtf8(),  &parseError);
             if (parseError.error != QJsonParseError::NoError) {
-                qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
+                qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
 	    } else if (yeasts.isArray()) {
 		for (int i = 0; i < yeasts.array().size(); i++) {
 		    QJsonObject obj = yeasts.array().at(i).toObject();
-		    //qDebug() << i << obj;
 		    Yeasts y;
 		    /* First some defaults for newer fields. */
 		    y.y_tolerance = y.y_harvest_time = y.y_pitch_temperature = y.y_zymocide = 0;
@@ -508,11 +504,10 @@
             const auto& formattedJson = QString("%1").arg(ma_json);
             QJsonDocument mashs = QJsonDocument::fromJson(formattedJson.toUtf8(),  &parseError);
             if (parseError.error != QJsonParseError::NoError) {
-                qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
+                qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
 	    } else if (mashs.isArray()) {
         	for (int i = 0; i < mashs.array().size(); i++) {
             	    QJsonObject obj = mashs.array().at(i).toObject();
-		    qDebug() << i << obj;
 		    Mashs m;
 		    m.step_name = obj["step_name"].toString();
 		    m.step_type = obj["step_type"].toInt();
@@ -1061,7 +1056,7 @@
     query.exec();
     qDebug() << query.lastQuery();
     if (query.lastError().isValid()) {
-	qDebug() << "saveProduct" << query.lastError();
+	qWarning() << "saveProduct" << query.lastError();
 	QMessageBox::warning(dialog, QObject::tr("Database error"),
                         QObject::tr("MySQL error: %1\n%2\n%3")
                         .arg(query.lastError().nativeErrorCode())
@@ -1077,9 +1072,9 @@
 	if (prod->record < 0) {
 		QVariant id = query.lastInsertId();
 		prod->record = id.toInt();
-		qDebug() << "saveProduct Inserted record" << prod->record;
+		qInfo() << "saveProduct Inserted record" << prod->record;
 	} else {
-		qDebug() << "saveProduct Updated record" << prod->record;
+		qInfo() << "saveProduct Updated record" << prod->record;
 	}
     }
     return true;
@@ -1094,7 +1089,7 @@
     query.bindValue(":recno", recno);
     query.exec();
     if (query.lastError().isValid()) {
-        qDebug() << "deleteProduct" << query.lastError();
+        qWarning() << "deleteProduct" << query.lastError();
         QMessageBox::warning(dialog, QObject::tr("Database error"),
                         QObject::tr("MySQL error: %1\n%2\n%3")
                         .arg(query.lastError().nativeErrorCode())
@@ -1103,7 +1098,7 @@
 	return false;
     }
 
-    qDebug() << "deleteProduct Deleted" << recno;
+    qInfo() << "deleteProduct Deleted" << recno;
     return true;
 }
 
--- a/src/database/db_recipe.cpp	Sun Jun 05 20:54:58 2022 +0200
+++ b/src/database/db_recipe.cpp	Sun Jun 05 21:10:06 2022 +0200
@@ -27,7 +27,7 @@
     query.bindValue(":recno", recno);
     query.exec();
     if (! query.first()) {
-	qDebug() << "loadRecipe seek error record" << recno;
+	qWarning() << "loadRecipe seek error record" << recno;
 	QMessageBox::warning(dialog, QObject::tr("Database error"), QObject::tr("MySQL error: record %1 not found").arg(recno));
 	dialog->done(QDialog::Rejected);	// At this stage, this doesn't work because the dialog is not yet visible.
 	return false;
@@ -132,7 +132,7 @@
 	const auto& formattedJson = QString("%1").arg(f_json);
 	QJsonDocument fermentables = QJsonDocument::fromJson(formattedJson.toUtf8(),  &parseError);
 	if (parseError.error != QJsonParseError::NoError) {
-            qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
+            qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
 	} else if (fermentables.isArray()) {
 	    double percentcheck = 0;
 	    for (int i = 0; i < fermentables.array().size(); i++) {
@@ -176,7 +176,7 @@
 			if (reci->fermentables.at(i).f_added < 4)
 			    reci->fermentables[i].f_percentage = round((reci->fermentables.at(i).f_amount / total) * 10000.0) / 100.0;
 		}
-		qDebug() << " fixed missing percentages";
+		qInfo() << "fixed missing percentages";
 	    }
 	}
     } else {
@@ -188,7 +188,7 @@
         const auto& formattedJson = QString("%1").arg(h_json);
         QJsonDocument hops = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
         if (parseError.error != QJsonParseError::NoError) {
-            qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset;
+            qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset;
 	} else if (hops.isArray()) {
 	    for (int i = 0; i < hops.array().size(); i++) {
 		QJsonObject obj = hops.array().at(i).toObject();
@@ -221,7 +221,7 @@
 	const auto& formattedJson = QString("%1").arg(m_json);
 	QJsonDocument miscs = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
 	if (parseError.error != QJsonParseError::NoError) {
-	    qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset;
+	    qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset;
 	} else if (miscs.isArray()) {
 	    for (int i = 0; i < miscs.array().size(); i++) {
 		QJsonObject obj = miscs.array().at(i).toObject();
@@ -245,7 +245,7 @@
 	const auto& formattedJson = QString("%1").arg(y_json);
 	QJsonDocument yeasts = QJsonDocument::fromJson(formattedJson.toUtf8(),  &parseError);
 	if (parseError.error != QJsonParseError::NoError) {
-	    qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
+	    qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
 	} else if (yeasts.isArray()) {
 	    for (int i = 0; i < yeasts.array().size(); i++) {
 		QJsonObject obj = yeasts.array().at(i).toObject();
@@ -326,7 +326,7 @@
 	const auto& formattedJson = QString("%1").arg(ma_json);
 	QJsonDocument mashs = QJsonDocument::fromJson(formattedJson.toUtf8(),  &parseError);
 	if (parseError.error != QJsonParseError::NoError) {
-	    qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
+	    qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
 	} else if (mashs.isArray()) {
 	    for (int i = 0; i < mashs.array().size(); i++) {
             	QJsonObject obj = mashs.array().at(i).toObject();
@@ -348,7 +348,7 @@
 	qDebug() << "empty mashs";
     }
 
-    qDebug() << "loadRecipe" << reci->record << "done";
+    qInfo() << "loadRecipe" << reci->record << "done";
     return true;
 }
 
@@ -649,7 +649,7 @@
     query.exec();
     qDebug() << query.lastQuery();
     if (query.lastError().isValid()) {
-	qDebug() << "EditRecipe" << query.lastError();
+	qWarning() << "EditRecipe" << query.lastError();
 	QMessageBox::warning(dialog, QObject::tr("Database error"),
                         QObject::tr("MySQL error: %1\n%2\n%3")
                         .arg(query.lastError().nativeErrorCode())
@@ -665,9 +665,9 @@
 	if (reci->record < 0) {
 	    QVariant id = query.lastInsertId();
 	    reci->record = id.toInt();
-	    qDebug() << "saveRecipe Inserted record" << reci->record;
+	    qInfo() << "saveRecipe Inserted record" << reci->record;
 	} else {
-	    qDebug() << "saveRecipe Updated record" << reci->record;
+	    qInfo() << "saveRecipe Updated record" << reci->record;
 	}
     }
     return true;
@@ -682,7 +682,7 @@
     query.bindValue(":recno", recno);
     query.exec();
     if (query.lastError().isValid()) {
-	qDebug() << "deleteRecipe" << query.lastError();
+	qWarning() << "deleteRecipe" << query.lastError();
 	QMessageBox::warning(dialog, QObject::tr("Database error"),
                         QObject::tr("MySQL error: %1\n%2\n%3")
                         .arg(query.lastError().nativeErrorCode())
@@ -691,7 +691,7 @@
 	return false;
     }
 
-    qDebug() << "deleteRecipe Deleted" << recno;
+    qInfo() << "deleteRecipe Deleted" << recno;
     return true;
 }
 

mercurial