Use static log structure
This commit is contained in:
parent
a844cf6ae4
commit
8baddbf003
14
src/log.cpp
14
src/log.cpp
|
@ -12,7 +12,7 @@ auto t2str(EntryType type) -> std::string {
|
|||
return "Type: None";
|
||||
}
|
||||
|
||||
void addEntry(Log& log, const std::string& msg, EntryType type) {
|
||||
void addEntry(const std::string& msg, EntryType type) {
|
||||
Entry ev;
|
||||
ev.type = type;
|
||||
ev.mesg = msg;
|
||||
|
@ -25,19 +25,19 @@ void addEntry(Log& log, const std::string& msg, EntryType type) {
|
|||
ev.creationDate.month = currentTime->tm_mon;
|
||||
ev.creationDate.year = currentTime->tm_year + 1900;
|
||||
|
||||
if (!log.entries)
|
||||
log.entries = new std::vector<Entry>();
|
||||
log.entries->push_back(ev);
|
||||
if (!s_log.entries)
|
||||
s_log.entries = new std::vector<Entry>();
|
||||
s_log.entries->push_back(ev);
|
||||
}
|
||||
|
||||
void writeLog(const Log& log, const std::string& loc, bool append) {
|
||||
void writeLog(const std::string& loc, bool append) {
|
||||
std::fstream f;
|
||||
if (append)
|
||||
f.open(LOC_LOG, std::fstream::out | std::fstream::app);
|
||||
else
|
||||
f.open(LOC_LOG);
|
||||
|
||||
for (auto entry: *log.entries) {
|
||||
for (auto entry: *s_log.entries) {
|
||||
f << "[ " << entry.creationDate.day << "/" << entry.creationDate.month
|
||||
<< "/" << entry.creationDate.year << " ] "
|
||||
<< "[ " << std::to_string(entry.timerTime) << " ] "
|
||||
|
@ -46,7 +46,7 @@ void writeLog(const Log& log, const std::string& loc, bool append) {
|
|||
f.close();
|
||||
}
|
||||
|
||||
void printLog(Log& log, const std::string& loc, int entries) {
|
||||
void printLog(const std::string& loc, int entries) {
|
||||
std::fstream f(LOC_LOG);
|
||||
std::string line = "";
|
||||
while (f >> line) { std::cout << line; }
|
||||
|
|
10
src/log.h
10
src/log.h
|
@ -7,12 +7,12 @@
|
|||
#include "data.h"
|
||||
#include "timer.h"
|
||||
|
||||
void addEntry(Log& log, const std::string& msg, EntryType type);
|
||||
void writeLog(const Log& log,
|
||||
const std::string& loc,
|
||||
static Log s_log;
|
||||
|
||||
void addEntry(const std::string& msg, EntryType type);
|
||||
void writeLog(const std::string& loc,
|
||||
bool append = true /* false == overwrite */);
|
||||
void printLog(Log& log,
|
||||
const std::string& loc,
|
||||
void printLog(const std::string& loc,
|
||||
int entries = 0 /* 0 == None, -1 == All */);
|
||||
|
||||
#endif
|
||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -33,8 +33,7 @@ void dispatch_Mod(std::string mod, std::vector<std::string> args) {
|
|||
|
||||
int main(int argc, const char* argv[]) {
|
||||
timer_start();
|
||||
Log log;
|
||||
addEntry(log, "Started Program.", EntryType::None);
|
||||
addEntry("Started Program.", EntryType::None);
|
||||
using namespace boost::program_options;
|
||||
using namespace std;
|
||||
|
||||
|
@ -59,7 +58,7 @@ int main(int argc, const char* argv[]) {
|
|||
|
||||
if (vm.count("help")) {
|
||||
std::cout << general << "\n";
|
||||
writeLog(log, LOC_LOG);
|
||||
writeLog(LOC_LOG);
|
||||
timer_stop();
|
||||
exit(0);
|
||||
} else if (vm.count("help-module")) {
|
||||
|
@ -67,7 +66,7 @@ int main(int argc, const char* argv[]) {
|
|||
auto module = get_Mod(name);
|
||||
if (!module) {
|
||||
std::cout << "Module not found.\n";
|
||||
writeLog(log, LOC_LOG);
|
||||
writeLog(LOC_LOG);
|
||||
timer_stop();
|
||||
exit(1);
|
||||
}
|
||||
|
@ -76,7 +75,7 @@ int main(int argc, const char* argv[]) {
|
|||
auto name = vm["module"].as<string>();
|
||||
if (!get_Mod(name)) {
|
||||
std::cout << "Module not found.\n";
|
||||
writeLog(log, LOC_LOG);
|
||||
writeLog(LOC_LOG);
|
||||
timer_stop();
|
||||
exit(1);
|
||||
}
|
||||
|
@ -87,7 +86,7 @@ int main(int argc, const char* argv[]) {
|
|||
dispatch_Mod(name, {""});
|
||||
} else {
|
||||
std::cout << general << "\n";
|
||||
writeLog(log, LOC_LOG);
|
||||
writeLog(LOC_LOG);
|
||||
timer_stop();
|
||||
exit(0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue