diff --git a/framework/logger/log.h b/framework/logger/log.h index 5602e4a..4409fb1 100644 --- a/framework/logger/log.h +++ b/framework/logger/log.h @@ -45,7 +45,7 @@ public: //print header if present if(Open() && mHeader.size()) { - SendMessage((char*)mHeader.c_str()); + SendMessage((char*)mHeader.c_str(), severity); } } @@ -56,7 +56,7 @@ public: FormatString(fmt, args); va_end(args); FormatPostfix(); - SendMessage(mString); + SendMessage(mString, severity); mLock.Unlock(); } @@ -121,7 +121,7 @@ public: protected: //actually sends message to the source - virtual void SendMessage(const char* msg) = 0; + virtual void SendMessage(const char* msg, SC_LogSeverity severity = SEVERITY_DEBUG) = 0; //format message prefix virtual void FormatPrefix(SC_LogSeverity severity); diff --git a/framework/logger/log_console.h b/framework/logger/log_console.h index 548a785..eb2991c 100644 --- a/framework/logger/log_console.h +++ b/framework/logger/log_console.h @@ -3,6 +3,11 @@ #include "log.h" +#define RED "\e[0;31m" +#define GREEN "\e[0;32m" +#define YELLOW "\e[1;33m" +#define NC "\e[0m" // No Color + class SC_LogConsole : public SC_LogBase { public: @@ -21,8 +26,27 @@ public: return true; } protected: - inline virtual void SendMessage(const char* msg) { - fprintf(stderr, "%s", msg); + inline virtual void SendMessage(const char* msg, SC_LogSeverity severity) { + const char* color = NC; + switch(severity) { + case SEVERITY_DEBUG: + color = NC; + break; + case SEVERITY_ERROR: + color = RED; + break; + case SEVERITY_INFO: + color = GREEN; + break; + case SEVERITY_WARNING: + color = YELLOW; + break; + default: + color = NC; + break; + } + + fprintf(stderr, "%s%s%s", color, msg, NC); } }; diff --git a/framework/logger/log_file.h b/framework/logger/log_file.h index 08aa43c..f1ef869 100644 --- a/framework/logger/log_file.h +++ b/framework/logger/log_file.h @@ -83,7 +83,7 @@ public: protected: - inline virtual void SendMessage(const char* msg) + inline virtual void SendMessage(const char* msg, SC_LogSeverity severity = SEVERITY_DEBUG) { if(mFile && mBytesCount < mMaxFileSize) { if(fputs(msg, mFile) >= 0) {