Use logger

This commit is contained in:
realaltffour 2020-04-14 17:00:40 +03:00
parent b02f1d4993
commit 8515e6cc6e
No known key found for this signature in database
GPG Key ID: 7115CD2AC9A76A56
6 changed files with 14 additions and 6 deletions

View File

@ -1,4 +1,5 @@
#include "data.h"
#include "log.h"
void to_json(json& j, const Date& date) {
j = json{{"day", date.day}, {"month", date.day}, {"year", date.year}};
@ -59,11 +60,10 @@ void from_json(const json& j, DB& db) {
void writeDB(DB db, const std::string& dest) {
try {
std::cout << "Writing database..." << std::endl;
logEntry("Writing Database...", EntryType::Modification);
std::ofstream f(dest);
json j = db;
f << j;
std::cout << "Wrote database successfully!" << std::endl;
} catch (std::exception& ex) {
std::cout << "Failed writing database to: " << dest << std::endl;
std::cout << "Error: " << ex.what() << std::endl;
@ -75,7 +75,7 @@ bool is_empty(std::ifstream& pFile) {
void loadDB(DB& db, const std::string& src) {
try {
std::cout << "Loading database..." << std::endl;
logEntry("Loading Database...", EntryType::Access);
std::ifstream f(src);
json j;
if (is_empty(f)) {
@ -85,7 +85,6 @@ void loadDB(DB& db, const std::string& src) {
}
f >> j;
db = j;
std::cout << "Loaded database successfully!" << std::endl;
} catch (const std::exception& ex) {
std::cout << "Failed loading database from: " << src << std::endl;
std::cout << "Error: " << ex.what() << std::endl;

View File

@ -93,5 +93,7 @@ int main(int argc, const char* argv[]) {
} catch (const error& ex) { cerr << ex.what() << '\n'; }
writeLog(LOC_LOG);
timer_stop();
return 0;
}

View File

@ -20,7 +20,7 @@ void init_create(init_args arg) {
db.projects = new std::map<std::string, Project>();
db.log.entries = new std::vector<Entry>();
// TODO: Add event logging
logEntry("Creating database.", EntryType::Creation);
writeDB(db, ".db");
}

View File

@ -6,6 +6,8 @@
#include <iostream>
#include <vector>
#include "../data.h"
#include "../log.h"
#include "module.h"
struct init_args {};

View File

@ -6,6 +6,8 @@
#include <boost/uuid/uuid_io.hpp> // streaming operators etc.
void proj_add(proj_args args) {
logEntry("Creating project with name: " + args.action_param,
EntryType::Creation);
Project proj;
proj.name = args.action_param;
@ -37,13 +39,15 @@ void proj_add(proj_args args) {
}
void proj_rm(proj_args args) {
logEntry("Removing project with name: " + args.action_param,
EntryType::Modification);
/* Delete project from database */
for (auto it = args.db->projects->begin(); it != args.db->projects->end();
it++) {
if (it->second.name == args.action_param) {
args.db->projects->erase(it);
writeDB(*args.db, ".db");
std::cout << "Deleted project successfully!" << std::endl;
logEntry("Deleted project successfully!", EntryType::Modification);
exit(0);
}
}

View File

@ -7,6 +7,7 @@
#include <vector>
#include "data.h"
#include "log.h"
#include "module.h"
enum projActType { Add, Remove, List };