Browse Source

Add comment as a color to log

master
Riyyi 3 years ago
parent
commit
61b061d55a
  1. 9
      inferno/src/inferno/log.cpp
  2. 9
      inferno/src/inferno/log.h

9
inferno/src/inferno/log.cpp

@ -126,7 +126,7 @@ namespace Inferno {
const LogStream& operator<<(const LogStream& stream, Log value)
{
switch (value) {
case Log::Log:
case Log::None:
return stream << "Log";
case Log::Info:
return stream << "Info";
@ -136,6 +136,8 @@ namespace Inferno {
return stream << "Danger";
case Log::Success:
return stream << "Success";
case Log::Comment:
return stream << "Comment";
default:
ASSERT_NOT_REACHED();
return stream;
@ -218,7 +220,7 @@ namespace Inferno {
DebugLogStream::~DebugLogStream()
{
if (m_type != Log::Log) {
if (m_type != Log::None) {
write("\033[0m", 4);
}
@ -243,6 +245,9 @@ namespace Inferno {
else if (m_type == Log::Success) {
color = "\x1B[32m";
}
else if (m_type == Log::Comment) {
color = "\x1B[37m";
}
if (color[0] != '\0') {
write(color, 5);

9
inferno/src/inferno/log.h

@ -8,11 +8,12 @@
namespace Inferno {
enum class Log {
Log,
None,
Info,
Warn,
Danger,
Success,
Comment,
};
// ----------------------------------------
@ -31,9 +32,9 @@ namespace Inferno {
class DebugLogStream final : public LogStream{
public:
DebugLogStream():
m_newline(true), m_type(Log::Log) {}
m_newline(true), m_type(Log::None) {}
DebugLogStream(bool newline):
m_newline(newline), m_type(Log::Log) {}
m_newline(newline), m_type(Log::None) {}
DebugLogStream(Log type):
m_newline(true), m_type(type) { color(); }
DebugLogStream(Log type, bool newline):
@ -102,7 +103,7 @@ namespace Inferno {
template<typename T, typename... P>
void dbgln(const char* format, T value, const P&... parameters)
{
dbgln(Log::Log, true, format, value, parameters...);
dbgln(Log::None, true, format, value, parameters...);
}
template<typename T, typename... P>

Loading…
Cancel
Save