Adds logging level tag to log messages
This commit is contained in:
1 parent
d2d4a21f94
commit
07812d62cd
2 files changed
+31
-23
No files matched your search
+28
-20
@@ -58,69 +58,77 @@ void Logger::log(Level lvl, const char* msg) {
|
||||
}
|
||||
|
||||
Logger::Sink::Sink (const Level level, Logger& parent) :
|
||||
level(level),
|
||||
parent(parent),
|
||||
lineIsPrefixed(false) {}
|
||||
level_(level),
|
||||
parent_(parent),
|
||||
lineIsPrefixed_(false) {}
|
||||
|
||||
void Logger::Sink::ln ( const string& msg ) {
|
||||
ln(msg.c_str());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::Sink::prefixLine(bool resetToFalse) {
|
||||
if (!lineIsPrefixed) {
|
||||
*parent.output << Logger::genTimeStamp() << " ";
|
||||
lineIsPrefixed = resetToFalse ? false : true;
|
||||
if (!lineIsPrefixed_) {
|
||||
const char* lvlString;
|
||||
switch ( level_ )
|
||||
{
|
||||
case DEBUG: lvlString = "DEBUG"; break;
|
||||
case INFO: lvlString = "INFO"; break;
|
||||
case WARN: lvlString = "WARN"; break;
|
||||
case FATAL: lvlString = "FATAL"; break;
|
||||
}
|
||||
*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 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;
|
||||
lineIsPrefixed = false;
|
||||
*parent_.output << endl;
|
||||
lineIsPrefixed_ = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user