diff options
author | Uwe Klotz <uwe_klotz@web.de> | 2017-06-03 12:59:44 +0200 |
---|---|---|
committer | Uwe Klotz <uwe_klotz@web.de> | 2017-06-12 07:30:17 +0200 |
commit | 82bf43628261182b8630bf647367c79f24fd2e36 (patch) | |
tree | 9370f39030d1848d152a6e8e6106e6d4f89ca018 /src/util | |
parent | 152314fa2bb6c58095103f453247656e77fb50db (diff) |
Improve database logging
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/db/fwdsqlquery.cpp | 38 | ||||
-rw-r--r-- | src/util/db/sqltransaction.cpp | 36 |
2 files changed, 41 insertions, 33 deletions
diff --git a/src/util/db/fwdsqlquery.cpp b/src/util/db/fwdsqlquery.cpp index 74d4df8f08..293dd8e18f 100644 --- a/src/util/db/fwdsqlquery.cpp +++ b/src/util/db/fwdsqlquery.cpp @@ -2,8 +2,6 @@ #include <QSqlRecord> -#include <QtDebug> - #include "util/performancetimer.h" #include "util/logger.h" #include "util/assert.h" @@ -41,9 +39,10 @@ FwdSqlQuery::FwdSqlQuery( m_prepared(prepareQuery(*this, statement)) { if (!m_prepared) { DEBUG_ASSERT(!database.isOpen() || hasError()); - qCritical() << "Failed to prepare SQL query" - << "for [" << statement << "]" - << "on [" << database.connectionName() << "]:" + kLogger.critical() + << "Failed to prepare" + << statement + << ":" << lastError(); } } @@ -70,16 +69,11 @@ bool FwdSqlQuery::execPrepared() { DEBUG_ASSERT(size() < 0); return true; } else { - if (lastQuery() == executedQuery()) { - qCritical() << "Failed to execute prepared SQL query" - << "lastQuery [" << lastQuery() << "]:" - << lastError(); - } else { - qCritical() << "Failed to execute prepared SQL query" - << "lastQuery [" << lastQuery() << "]" - << "executedQuery [" << executedQuery() << "]:" - << lastError(); - } + kLogger.warning() + << "Failed to execute" + << lastQuery() + << ":" + << lastError(); DEBUG_ASSERT(hasError()); return false; } @@ -90,9 +84,9 @@ DbFieldIndex FwdSqlQuery::fieldIndex(const QString& fieldName) const { DEBUG_ASSERT(isSelect()); DbFieldIndex fieldIndex(record().indexOf(fieldName)); VERIFY_OR_DEBUG_ASSERT(fieldIndex.isValid()) { - qCritical() << "Field named" - << fieldName - << "not found in record of SQL query" + kLogger.critical() + << "Field named" << fieldName + << "not found in result from" << executedQuery(); } DEBUG_ASSERT(!hasError()); @@ -112,12 +106,16 @@ namespace { bool ok = false; int value = variant.toInt(&ok); VERIFY_OR_DEBUG_ASSERT(ok) { - qWarning() << "Invalid boolean value in database:" << variant; + kLogger.critical() + << "Invalid boolean value in database:" + << variant; } VERIFY_OR_DEBUG_ASSERT( (value == FwdSqlQuery::BOOLEAN_FALSE) || (value == FwdSqlQuery::BOOLEAN_TRUE)) { - qWarning() << "Invalid boolean value in database:" << value; + kLogger.critical() + << "Invalid boolean value in database:" + << value; } // C-style conversion from int to bool DEBUG_ASSERT(FwdSqlQuery::BOOLEAN_FALSE == 0); diff --git a/src/util/db/sqltransaction.cpp b/src/util/db/sqltransaction.cpp index 6bd1a9d8b6..25234e0ff1 100644 --- a/src/util/db/sqltransaction.cpp +++ b/src/util/db/sqltransaction.cpp @@ -1,26 +1,30 @@ #include "util/db/sqltransaction.h" -#include <QtDebug> - +#include "util/logger.h" #include "util/assert.h" namespace { + const mixxx::Logger kLogger("SqlTransaction"); + inline bool beginTransaction(QSqlDatabase& database) { if (!database.isOpen()) { // Should only happen during tests - qWarning() << "Failed to begin SQL database transaction on" + kLogger.warning() + << "Failed to begin SQL database transaction on" << database.connectionName(); return false; } if (database.transaction()) { - qDebug() << "Started new SQL database transaction on" - << database.connectionName(); + kLogger.debug() + << "Started new SQL database transaction on" + << database.connectionName(); return true; } else { - qWarning() << "Failed to begin SQL database transaction on" - << database.connectionName(); + kLogger.warning() + << "Failed to begin SQL database transaction on" + << database.connectionName(); return false; } } @@ -51,16 +55,19 @@ void SqlTransaction::release() { bool SqlTransaction::commit() { DEBUG_ASSERT(m_active); if (!m_database.isOpen()) { - qWarning() << "Failed to commit transaction: No open SQL database connection"; + kLogger.warning() + << "Failed to commit transaction: No open SQL database connection"; return false; } if (m_database.commit()) { - qDebug() << "Committed SQL database transaction on" + kLogger.debug() + << "Committed SQL database transaction on" << m_database.connectionName(); release(); // commit/rollback only once return true; } else { - qWarning() << "Failed to commit SQL database transaction on" + kLogger.warning() + << "Failed to commit SQL database transaction on" << m_database.connectionName(); return false; } @@ -69,16 +76,19 @@ bool SqlTransaction::commit() { bool SqlTransaction::rollback() { DEBUG_ASSERT(m_active); if (!m_database.isOpen()) { - qWarning() << "Failed to rollback transaction: No open SQL database connection"; + kLogger.warning() + << "Failed to rollback transaction: No open SQL database connection"; return false; } if (m_database.rollback()) { - qDebug() << "Rolled back SQL database transaction on" + kLogger.debug() + << "Rolled back SQL database transaction on" << m_database.connectionName(); release(); // commit/rollback only once return true; } else { - qWarning() << "Failed to rollback SQL database transaction on" + kLogger.warning() + << "Failed to rollback SQL database transaction on" << m_database.connectionName(); return false; } |