Colored text & console log support for C++
- C++11 or later
- POSIX-compatible environment (Linux, macOS)
#include "text_support.h"textSupport::debugMessage("something happened");
textSupport::infoMessage("server started");
textSupport::warningMessage("retrying connection");
textSupport::errorMessage("file not found");
textSupport::fatalMessage("unrecoverable error");Use log() to select the level at call site:
textSupport::log(textSupport::LogLevel::Debug, "debug message");
textSupport::log(textSupport::LogLevel::Info, "info message");
textSupport::log(textSupport::LogLevel::Warning, "warning message");
textSupport::log(textSupport::LogLevel::Error, "error message");
textSupport::log(textSupport::LogLevel::Fatal, "fatal message");Edit LOG_TABLE in text_support.cpp and add a corresponding entry to the LogLevel enum in text_support.h:
// text_support.h
enum class LogLevel { Debug, Info, Warning, Error, Fatal, Verbose }; // add here
// text_support.cpp
static const LogEntry LOG_TABLE[] = {
/* Debug */ { "DBG", TEXT_SUPPORT_BLUE, &std::cout },
/* Info */ { "INFO", TEXT_SUPPORT_CYAN, &std::cout },
/* Warning */ { "WARN", TEXT_SUPPORT_YELLOW, &std::cout },
/* Error */ { "ERR", TEXT_SUPPORT_RED, &std::cerr },
/* Fatal */ { "FATAL", TEXT_SUPPORT_BOLDRED, &std::cerr },
/* Verbose */ { "VERBOSE", TEXT_SUPPORT_WHITE, &std::cout }, // add here
};The following macros are available for direct use:
| Macro | Color |
|---|---|
TEXT_SUPPORT_RESET |
Reset |
TEXT_SUPPORT_BLACK |
Black |
TEXT_SUPPORT_RED |
Red |
TEXT_SUPPORT_GREEN |
Green |
TEXT_SUPPORT_YELLOW |
Yellow |
TEXT_SUPPORT_BLUE |
Blue |
TEXT_SUPPORT_MAGENTA |
Magenta |
TEXT_SUPPORT_CYAN |
Cyan |
TEXT_SUPPORT_WHITE |
White |
TEXT_SUPPORT_BOLD* |
Bold variants of the above |
g++ -std=c++11 your_program.cpp text_support.cpp -o your_programCopyright (c) 2017 FRONTL1NE All rights reserved
