summaryrefslogtreecommitdiff
path: root/src/log.h
diff options
context:
space:
mode:
authoryou <ovvv@web.de>2018-03-04 17:34:36 +0100
committerSmallJoker <SmallJoker@users.noreply.github.com>2018-03-04 17:34:36 +0100
commit540e07e3ef07de760100c2948dc3a756e48b1c72 (patch)
tree80faec4d957688f1f83c5285386c2d413de3413d /src/log.h
parent929792e15ea50943e7fd23925c3d1d431dfd8a02 (diff)
downloadminetest-540e07e3ef07de760100c2948dc3a756e48b1c72.tar.gz
minetest-540e07e3ef07de760100c2948dc3a756e48b1c72.tar.bz2
minetest-540e07e3ef07de760100c2948dc3a756e48b1c72.zip
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.
Diffstat (limited to 'src/log.h')
-rw-r--r--src/log.h26
1 files changed, 16 insertions, 10 deletions
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 <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 {