This commit is contained in:
Suraxius committed 2021-03-10 23:34:34 +01:00
1 parent eb8bc7a696
commit 1dd457d2d2
5 files changed
+74 -70

No files matched your search

+24 -24
View File
@@ -10,26 +10,27 @@ using std::cerr;
using std::endl;
Logger::Logger(enum Level logLevel) :
logLevel(logLevel),
_logLevel(logLevel),
debug(DEBUG, *this),
info(INFO, *this),
warn(WARN, *this),
fatal(FATAL, *this)
{
output = new ofstream("plains.log", std::ios_base::app);
_output = new ofstream("plains.log", std::ios_base::app);
if (!(*output)) {
if (!(*_output)) {
cout << "Unable to open Logfile! writing to /tmp/plains.log" << endl;
output = new ofstream("/tmp/plains.log");
_output = new ofstream("/tmp/plains.log");
}
else {
debug << "============================" << commit;
debug << "Logfile successfully opened!" << commit;
}
}
Logger::~Logger() {
output->close();
delete output;
_output->close();
delete _output;
}
string Logger::genTimeStamp() {
@@ -43,8 +44,7 @@ string Logger::genTimeStamp() {
return string(buffer);
}
void Logger::setLogLevel(Level level) {
}
void Logger::setLogLevel(Level level) { _logLevel = level; }
void Logger::log(Level lvl, const string& msg) { log ( lvl, msg.c_str() ); }
@@ -67,11 +67,11 @@ void Logger::Sink::ln ( const string& msg ) {
}
void Logger::Sink::ln ( const char* msg ) {
if ( _level>= _parent.logLevel ) {
if ( _level >= _parent._logLevel ) {
// If line has already been started, abort it and start new one:
if(_lineIsPrefixed) *_parent.output << endl;
if(_lineIsPrefixed) *_parent._output << endl;
prefixLine(true);
*_parent.output << msg << endl;
*_parent._output << msg << endl;
}
}
@@ -85,58 +85,58 @@ void Logger::Sink::prefixLine(bool resetToFalse) {
case WARN: lvlString = "WARN"; break;
case FATAL: lvlString = "FATAL"; break;
}
*_parent.output << Logger::genTimeStamp() << " [" << lvlString << "] ";
*_parent._output << Logger::genTimeStamp() << " [" << lvlString << "] ";
_lineIsPrefixed = resetToFalse ? false : true;
}
}
Logger::Sink& Logger::Sink::operator<<(const string& msg) {
if ( _level>= _parent.logLevel ) {
if ( _level >= _parent._logLevel ) {
prefixLine();
*_parent.output << msg;
*_parent._output << msg;
}
return *this;
}
Logger::Sink& Logger::Sink::operator<<(const char* msg) {
if ( _level>= _parent.logLevel ) {
if ( _level >= _parent._logLevel ) {
prefixLine();
*_parent.output << msg;
*_parent._output << msg;
}
return *this;
}
Logger::Sink& Logger::Sink::operator<<(const int msg) {
if ( _level>= _parent.logLevel ) {
if ( _level >= _parent._logLevel ) {
prefixLine();
*_parent.output << msg;
*_parent._output << msg;
}
return *this;
}
Logger::Sink& Logger::Sink::operator<<(const long msg) {
if ( _level>= _parent.logLevel ) {
if ( _level >= _parent._logLevel ) {
prefixLine();
*_parent.output << msg;
*_parent._output << msg;
}
return *this;
}
Logger::Sink& Logger::Sink::operator<<(const unsigned long msg) {
if ( _level>= _parent.logLevel ) {
if ( _level >= _parent._logLevel ) {
prefixLine();
*_parent.output << msg;
*_parent._output << msg;
}
return *this;
}
Logger::Sink& Logger::Sink::operator<<(const char character) {
if ( _level>= _parent.logLevel ) {
if ( _level >= _parent._logLevel ) {
switch(character) {
// COMMIT - End message line
case 0:
*_parent.output << endl;
*_parent._output << endl;
_lineIsPrefixed = false;
break;
}