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.master
parent
929792e15e
commit
540e07e3ef
|
@ -1212,13 +1212,6 @@ language (Language) enum ,be,ca,cs,da,de,dv,en,eo,es,et,fr,he,hu,id,it,ja,jbo,
|
||||||
# - verbose
|
# - verbose
|
||||||
debug_log_level (Debug log level) enum action ,none,error,warning,action,info,verbose
|
debug_log_level (Debug log level) enum action ,none,error,warning,action,info,verbose
|
||||||
|
|
||||||
# ANSI colored logs: red error log, yellow warning and grey info and verbose logs
|
|
||||||
# Note that it doesn't work on Windows
|
|
||||||
# "yes" always enables it,
|
|
||||||
# "detect" enables it when printing to terminal and
|
|
||||||
# "no" disables it
|
|
||||||
log_color (Colored logs) enum detect yes,detect,no
|
|
||||||
|
|
||||||
# IPv6 support.
|
# IPv6 support.
|
||||||
enable_ipv6 (IPv6) bool true
|
enable_ipv6 (IPv6) bool true
|
||||||
|
|
||||||
|
|
|
@ -351,7 +351,6 @@ void set_default_settings(Settings *settings)
|
||||||
settings->setDefault("ignore_world_load_errors", "false");
|
settings->setDefault("ignore_world_load_errors", "false");
|
||||||
settings->setDefault("remote_media", "");
|
settings->setDefault("remote_media", "");
|
||||||
settings->setDefault("debug_log_level", "action");
|
settings->setDefault("debug_log_level", "action");
|
||||||
settings->setDefault("log_color", "detect");
|
|
||||||
settings->setDefault("emergequeue_limit_total", "256");
|
settings->setDefault("emergequeue_limit_total", "256");
|
||||||
settings->setDefault("emergequeue_limit_diskonly", "32");
|
settings->setDefault("emergequeue_limit_diskonly", "32");
|
||||||
settings->setDefault("emergequeue_limit_generate", "32");
|
settings->setDefault("emergequeue_limit_generate", "32");
|
||||||
|
|
|
@ -251,6 +251,8 @@ const std::string Logger::getLevelLabel(LogLevel lev)
|
||||||
return names[lev];
|
return names[lev];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LogColor Logger::color_mode = LOG_COLOR_AUTO;
|
||||||
|
|
||||||
const std::string Logger::getThreadName()
|
const std::string Logger::getThreadName()
|
||||||
{
|
{
|
||||||
std::map<std::thread::id, std::string>::const_iterator it;
|
std::map<std::thread::id, std::string>::const_iterator it;
|
||||||
|
|
26
src/log.h
26
src/log.h
|
@ -28,7 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#if !defined(_WIN32) // POSIX
|
#if !defined(_WIN32) // POSIX
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
#include "settings.h"
|
|
||||||
#include "irrlichttypes.h"
|
#include "irrlichttypes.h"
|
||||||
|
|
||||||
class ILogOutput;
|
class ILogOutput;
|
||||||
|
@ -43,6 +42,12 @@ enum LogLevel {
|
||||||
LL_MAX,
|
LL_MAX,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum LogColor {
|
||||||
|
LOG_COLOR_NEVER,
|
||||||
|
LOG_COLOR_ALWAYS,
|
||||||
|
LOG_COLOR_AUTO,
|
||||||
|
};
|
||||||
|
|
||||||
typedef u8 LogLevelMask;
|
typedef u8 LogLevelMask;
|
||||||
#define LOGLEVEL_TO_MASKLEVEL(x) (1 << x)
|
#define LOGLEVEL_TO_MASKLEVEL(x) (1 << x)
|
||||||
|
|
||||||
|
@ -68,6 +73,8 @@ public:
|
||||||
static LogLevel stringToLevel(const std::string &name);
|
static LogLevel stringToLevel(const std::string &name);
|
||||||
static const std::string getLevelLabel(LogLevel lev);
|
static const std::string getLevelLabel(LogLevel lev);
|
||||||
|
|
||||||
|
static LogColor color_mode;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void logToOutputsRaw(LogLevel, const std::string &line);
|
void logToOutputsRaw(LogLevel, const std::string &line);
|
||||||
void logToOutputs(LogLevel, const std::string &combined,
|
void logToOutputs(LogLevel, const std::string &combined,
|
||||||
|
@ -111,18 +118,17 @@ public:
|
||||||
m_stream(stream)
|
m_stream(stream)
|
||||||
{
|
{
|
||||||
#if !defined(_WIN32)
|
#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
|
#else
|
||||||
is_tty = false;
|
colored = Logger::color_mode == LOG_COLOR_ALWAYS;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void logRaw(LogLevel lev, const std::string &line)
|
void logRaw(LogLevel lev, const std::string &line)
|
||||||
{
|
{
|
||||||
static const std::string use_logcolor = g_settings->get("log_color");
|
bool colored_message = colored;
|
||||||
|
if (colored_message)
|
||||||
bool colored = use_logcolor == "detect" ? is_tty : use_logcolor == "yes";
|
|
||||||
if (colored)
|
|
||||||
switch (lev) {
|
switch (lev) {
|
||||||
case LL_ERROR:
|
case LL_ERROR:
|
||||||
// error is red
|
// error is red
|
||||||
|
@ -142,19 +148,19 @@ public:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// action is white
|
// action is white
|
||||||
colored = false;
|
colored_message = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_stream << line << std::endl;
|
m_stream << line << std::endl;
|
||||||
|
|
||||||
if (colored)
|
if (colored_message)
|
||||||
// reset to white color
|
// reset to white color
|
||||||
m_stream << "\033[0m";
|
m_stream << "\033[0m";
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::ostream &m_stream;
|
std::ostream &m_stream;
|
||||||
bool is_tty;
|
bool colored;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileLogOutput : public ICombinedLogOutput {
|
class FileLogOutput : public ICombinedLogOutput {
|
||||||
|
|
20
src/main.cpp
20
src/main.cpp
|
@ -266,6 +266,15 @@ static void set_allowed_options(OptionList *allowed_options)
|
||||||
"'name' lists names, 'both' lists both)"))));
|
"'name' lists names, 'both' lists both)"))));
|
||||||
allowed_options->insert(std::make_pair("quiet", ValueSpec(VALUETYPE_FLAG,
|
allowed_options->insert(std::make_pair("quiet", ValueSpec(VALUETYPE_FLAG,
|
||||||
_("Print to console errors only"))));
|
_("Print to console errors only"))));
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
allowed_options->insert(std::make_pair("color", ValueSpec(VALUETYPE_STRING,
|
||||||
|
_("Coloured logs ('always', 'never' or 'auto'), defaults to 'auto'"
|
||||||
|
))));
|
||||||
|
#else
|
||||||
|
allowed_options->insert(std::make_pair("color", ValueSpec(VALUETYPE_STRING,
|
||||||
|
_("Coloured logs ('always' or 'never'), defaults to 'never'"
|
||||||
|
))));
|
||||||
|
#endif
|
||||||
allowed_options->insert(std::make_pair("info", ValueSpec(VALUETYPE_FLAG,
|
allowed_options->insert(std::make_pair("info", ValueSpec(VALUETYPE_FLAG,
|
||||||
_("Print more information to console"))));
|
_("Print more information to console"))));
|
||||||
allowed_options->insert(std::make_pair("verbose", ValueSpec(VALUETYPE_FLAG,
|
allowed_options->insert(std::make_pair("verbose", ValueSpec(VALUETYPE_FLAG,
|
||||||
|
@ -393,6 +402,17 @@ static void setup_log_params(const Settings &cmd_args)
|
||||||
g_logger.addOutputMaxLevel(&stderr_output, LL_ERROR);
|
g_logger.addOutputMaxLevel(&stderr_output, LL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Coloured log messages (see log.h)
|
||||||
|
if (cmd_args.exists("color")) {
|
||||||
|
std::string mode = cmd_args.get("color");
|
||||||
|
if (mode == "auto")
|
||||||
|
Logger::color_mode = LOG_COLOR_AUTO;
|
||||||
|
else if (mode == "always")
|
||||||
|
Logger::color_mode = LOG_COLOR_ALWAYS;
|
||||||
|
else
|
||||||
|
Logger::color_mode = LOG_COLOR_NEVER;
|
||||||
|
}
|
||||||
|
|
||||||
// If trace is enabled, enable logging of certain things
|
// If trace is enabled, enable logging of certain things
|
||||||
if (cmd_args.getFlag("trace")) {
|
if (cmd_args.getFlag("trace")) {
|
||||||
dstream << _("Enabling trace level debug output") << std::endl;
|
dstream << _("Enabling trace level debug output") << std::endl;
|
||||||
|
|
Loading…
Reference in New Issue