1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

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.
This commit is contained in:
you 2018-03-04 17:34:36 +01:00 committed by SmallJoker
parent 929792e15e
commit 540e07e3ef
5 changed files with 38 additions and 18 deletions

View file

@ -28,7 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#if !defined(_WIN32) // POSIX
#include <unistd.h>
#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 {