|
|
@ -1,6 +1,9 @@ |
|
|
|
#include "../lib/log.hpp" |
|
|
|
#include "../lib/log.hpp" |
|
|
|
|
|
|
|
|
|
|
|
marcelb::log::log(string _dir, bool _isKeepOpen, bool _printInConsole) { |
|
|
|
namespace marcelb { |
|
|
|
|
|
|
|
namespace logging { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log::log(string _dir, bool _isKeepOpen, bool _printInConsole) { |
|
|
|
dir = _dir; |
|
|
|
dir = _dir; |
|
|
|
isKeepOpen = _isKeepOpen; |
|
|
|
isKeepOpen = _isKeepOpen; |
|
|
|
printInConsole = _printInConsole; |
|
|
|
printInConsole = _printInConsole; |
|
|
@ -21,28 +24,28 @@ marcelb::log::log(string _dir, bool _isKeepOpen, bool _printInConsole) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool marcelb::log::isdir() { |
|
|
|
bool log::isdir() { |
|
|
|
struct stat sb; |
|
|
|
struct stat sb; |
|
|
|
return stat(dir.c_str(), &sb) == 0; |
|
|
|
return stat(dir.c_str(), &sb) == 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool marcelb::log::open() { |
|
|
|
bool log::open() { |
|
|
|
logfile = ofstream (path, ios_base::app); |
|
|
|
logfile = ofstream (path, ios_base::app); |
|
|
|
return logfile.is_open(); |
|
|
|
return logfile.is_open(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void marcelb::log::loose() { |
|
|
|
void log::loose() { |
|
|
|
logfile.close(); |
|
|
|
logfile.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void marcelb::log::setMoment() { |
|
|
|
void log::setMoment() { |
|
|
|
time_t rawtime; |
|
|
|
time_t rawtime; |
|
|
|
time (&rawtime); |
|
|
|
time (&rawtime); |
|
|
|
moment = localtime (&rawtime); |
|
|
|
moment = localtime (&rawtime); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void marcelb::log::put(string logline) { |
|
|
|
void log::put(string logline) { |
|
|
|
io.lock(); |
|
|
|
io.lock(); |
|
|
|
if (printInConsole) { |
|
|
|
if (printInConsole) { |
|
|
|
cout << logline << endl; |
|
|
|
cout << logline << endl; |
|
|
@ -79,7 +82,7 @@ void marcelb::log::put(string logline) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void marcelb::log::setPath() { |
|
|
|
void log::setPath() { |
|
|
|
if (dir[dir.length()-1] != '/') { |
|
|
|
if (dir[dir.length()-1] != '/') { |
|
|
|
dir.push_back('/'); |
|
|
|
dir.push_back('/'); |
|
|
|
} |
|
|
|
} |
|
|
@ -90,7 +93,7 @@ void marcelb::log::setPath() { |
|
|
|
path = dir + to_string(moment->tm_year+1900) + '-' + mon.str() + '-' + _day.str() + ".log"; |
|
|
|
path = dir + to_string(moment->tm_year+1900) + '-' + mon.str() + '-' + _day.str() + ".log"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void marcelb::log::setPrefix(string &logline) { |
|
|
|
void log::setPrefix(string &logline) { |
|
|
|
stringstream hour, min, sec; |
|
|
|
stringstream hour, min, sec; |
|
|
|
hour << setw(2) << setfill('0') << moment->tm_hour; |
|
|
|
hour << setw(2) << setfill('0') << moment->tm_hour; |
|
|
|
min << setw(2) << setfill('0') << moment->tm_min; |
|
|
|
min << setw(2) << setfill('0') << moment->tm_min; |
|
|
@ -100,7 +103,10 @@ void marcelb::log::setPrefix(string &logline) { |
|
|
|
logline = _logline; |
|
|
|
logline = _logline; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
marcelb::log::~log() { |
|
|
|
log::~log() { |
|
|
|
loose(); |
|
|
|
loose(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|