X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Flog.h;h=506137739a06a9d6f3b861e8eae075127f679d34;hb=3face01a202040e4feff3b0936b4aa89c051c98d;hp=6a1c24dec64e2c52077d4519cff588288ab7f491;hpb=951f1201c413c1137cfbef771bdd575c9c7e01bb;p=oweals%2Fminetest.git diff --git a/src/log.h b/src/log.h index 6a1c24dec..506137739 100644 --- a/src/log.h +++ b/src/log.h @@ -25,6 +25,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#if !defined(_WIN32) // POSIX + #include +#endif +#include "settings.h" #include "irrlichttypes.h" class ILogOutput; @@ -106,15 +110,51 @@ public: StreamLogOutput(std::ostream &stream) : m_stream(stream) { +#if !defined(_WIN32) + is_tty = isatty(fileno(stdout)); +#else + is_tty = false; +#endif } void logRaw(LogLevel lev, const std::string &line) { + static const std::string use_logcolor = g_settings->get("log_color"); + + bool colored = use_logcolor == "detect" ? is_tty : use_logcolor == "yes"; + if (colored) + switch (lev) { + case LL_ERROR: + // error is red + m_stream << "\033[91m"; + break; + case LL_WARNING: + // warning is yellow + m_stream << "\033[93m"; + break; + case LL_INFO: + // info is a bit dark + m_stream << "\033[37m"; + break; + case LL_VERBOSE: + // verbose is darker than info + m_stream << "\033[2m"; + break; + default: + // action is white + colored = false; + } + m_stream << line << std::endl; + + if (colored) + // reset to white color + m_stream << "\033[0m"; } private: std::ostream &m_stream; + bool is_tty; }; class FileLogOutput : public ICombinedLogOutput {