From 540e07e3ef07de760100c2948dc3a756e48b1c72 Mon Sep 17 00:00:00 2001 From: you Date: Sun, 4 Mar 2018 17:34:36 +0100 Subject: Fix missing warningstream (or similar problem) (#7034) Use the --color command line parameter instead of a setting for coloured logs This fixes the missing warningstream bug, g_settings->get mustn't be used there. Also, the decision about en- or disabling log colours fits better to the command line parameters than minetest settings. --- src/log.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/log.h') diff --git a/src/log.h b/src/log.h index 506137739..952ebadb1 100644 --- a/src/log.h +++ b/src/log.h @@ -28,7 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #if !defined(_WIN32) // POSIX #include #endif -#include "settings.h" #include "irrlichttypes.h" class ILogOutput; @@ -43,6 +42,12 @@ enum LogLevel { LL_MAX, }; +enum LogColor { + LOG_COLOR_NEVER, + LOG_COLOR_ALWAYS, + LOG_COLOR_AUTO, +}; + typedef u8 LogLevelMask; #define LOGLEVEL_TO_MASKLEVEL(x) (1 << x) @@ -68,6 +73,8 @@ public: static LogLevel stringToLevel(const std::string &name); static const std::string getLevelLabel(LogLevel lev); + static LogColor color_mode; + private: void logToOutputsRaw(LogLevel, const std::string &line); void logToOutputs(LogLevel, const std::string &combined, @@ -111,18 +118,17 @@ public: m_stream(stream) { #if !defined(_WIN32) - is_tty = isatty(fileno(stdout)); + colored = (Logger::color_mode == LOG_COLOR_ALWAYS) || + (Logger::color_mode == LOG_COLOR_AUTO && isatty(fileno(stdout))); #else - is_tty = false; + colored = Logger::color_mode == LOG_COLOR_ALWAYS; #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) + bool colored_message = colored; + if (colored_message) switch (lev) { case LL_ERROR: // error is red @@ -142,19 +148,19 @@ public: break; default: // action is white - colored = false; + colored_message = false; } m_stream << line << std::endl; - if (colored) + if (colored_message) // reset to white color m_stream << "\033[0m"; } private: std::ostream &m_stream; - bool is_tty; + bool colored; }; class FileLogOutput : public ICombinedLogOutput { -- cgit v1.2.3