Skip to content
Snippets Groups Projects
Commit ea6a019d authored by Olivier Dion's avatar Olivier Dion
Browse files

logger: Add NO_COLOR for console logger

Change-Id: I02ccb3c2d05aaa14a7f42dd0c6e2854f9905ccf2
parent 21c8feb7
No related branches found
No related tags found
No related merge requests found
......@@ -297,6 +297,17 @@ public:
virtual void consume(jami::Logger::Msg& msg) override
{
static bool no_color = (getenv("NO_COLOR") ||
getenv("NO_COLORS") ||
getenv("NO_COLOUR") ||
getenv("NO_COLOURS"));
#if defined(_WIN32) && !defined(RING_UWP)
WORD saved_attributes;
HANDLE hConsole;
#endif
if (not no_color) {
#ifndef _WIN32
const char* color_header = CYAN;
const char* color_prefix = "";
......@@ -305,9 +316,9 @@ public:
WORD color_header = CYAN;
#endif
#if defined(_WIN32) && !defined(RING_UWP)
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
WORD saved_attributes;
#endif
switch (msg.level_) {
......@@ -335,6 +346,9 @@ public:
SetConsoleTextAttribute(hConsole, saved_attributes);
SetConsoleTextAttribute(hConsole, color_prefix);
#endif
} else {
fputs(msg.header_.c_str(), stderr);
}
fputs(msg.payload_.get(), stderr);
......@@ -342,11 +356,13 @@ public:
putc(ENDL, stderr);
}
if (not no_color) {
#ifndef _WIN32
fputs(END_COLOR, stderr);
#elif !defined(RING_UWP)
SetConsoleTextAttribute(hConsole, saved_attributes);
#endif
}
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment