Log: color console output by default (NO_COLOR opt-out)
This commit is contained in:
1 parent
3ce62c9cbd
commit
b3c1246291
2 files changed
+30
-4
No files matched your search
@@ -4,6 +4,7 @@
|
||||
#include <Void/Stacktrace/Color.hpp>
|
||||
#endif
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
@@ -15,12 +16,17 @@ namespace Void::Logging
|
||||
ColorPolicy console_default_policy()
|
||||
{
|
||||
ColorPolicy p = ColorPolicy::defaults();
|
||||
// Colored by default, with the standard opt-outs: NO_COLOR for
|
||||
// the environment and the Stacktrace global toggle when present.
|
||||
bool enabled = true;
|
||||
if (const char* no_color = std::getenv("NO_COLOR");
|
||||
no_color != nullptr && *no_color != '\0') {
|
||||
enabled = false;
|
||||
}
|
||||
#ifdef VOID_HAS_STACKTRACE
|
||||
// Honor the global color toggle when Stacktrace is present.
|
||||
p.enabled = Void::Stacktrace::Color::g_color_enabled;
|
||||
#else
|
||||
p.enabled = false;
|
||||
enabled = enabled && Void::Stacktrace::Color::g_color_enabled;
|
||||
#endif
|
||||
p.enabled = enabled;
|
||||
return p;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Reference in new issue
Block a user