colorize log messages written to console correspondingly to severity of
the message
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user