Add proper error logging to solar-logger
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <solar/logger/database.hpp>
|
#include <solar/logger/database.hpp>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <util/date.hpp>
|
#include <util/date.hpp>
|
||||||
@@ -42,12 +43,22 @@ bool Database::Insert(ZeverRow & row)
|
|||||||
std::stringstream transaction;
|
std::stringstream transaction;
|
||||||
transaction << "BEGIN TRANSACTION;" << ToSqlInsertStatement(row) << ToSqlUpsertStatement(row) << "COMMIT;";
|
transaction << "BEGIN TRANSACTION;" << ToSqlInsertStatement(row) << ToSqlUpsertStatement(row) << "COMMIT;";
|
||||||
|
|
||||||
return sqlite3_exec(connectionPtr, transaction.str().c_str(), nullptr, nullptr, nullptr);
|
if(sqlite3_exec(connectionPtr, transaction.str().c_str(), nullptr, nullptr, nullptr) != SQLITE_OK)
|
||||||
|
{
|
||||||
|
spdlog::error("Failed to insert Zeverlution record into SQLite database: {}", sqlite3_errmsg(connectionPtr));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Database::Insert(EnvoyRow & row)
|
bool Database::Insert(EnvoyRow & row)
|
||||||
{
|
{
|
||||||
return sqlite3_exec(connectionPtr, ToSqlInsertStatement(row).c_str(), nullptr, nullptr, nullptr);
|
if(sqlite3_exec(connectionPtr, ToSqlInsertStatement(row).c_str(), nullptr, nullptr, nullptr) != SQLITE_OK)
|
||||||
|
{
|
||||||
|
spdlog::error("Failed to insert Envoy record into SQLite database: {}", sqlite3_errmsg(connectionPtr));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Database::Database(std::string const & databasePath) : connectionPtr(nullptr)
|
Database::Database(std::string const & databasePath) : connectionPtr(nullptr)
|
||||||
|
|||||||
@@ -127,10 +127,8 @@ int main(int argc, char ** argv)
|
|||||||
.kilowattPerHour = zeverData->kilowattPerHour,
|
.kilowattPerHour = zeverData->kilowattPerHour,
|
||||||
};
|
};
|
||||||
|
|
||||||
auto const insertionResult = db.Insert(row);
|
if(!db.Insert(row))
|
||||||
if(insertionResult)
|
|
||||||
{
|
{
|
||||||
spdlog::error("Error {} during insertion of new value into database", insertionResult);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,10 +154,8 @@ int main(int argc, char ** argv)
|
|||||||
.inverterTime = parsed->readingTime,
|
.inverterTime = parsed->readingTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
auto const insertionResult = db.Insert(row);
|
if(!db.Insert(row))
|
||||||
if(insertionResult)
|
|
||||||
{
|
{
|
||||||
spdlog::error("Error {} during insertion of new value into database", insertionResult);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user