1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Ensure that null C strings do not break logging (#15255)

This commit is contained in:
paradust7 2024-10-12 13:34:24 -07:00 committed by GitHub
parent 4e6e8b7bf1
commit 2188adc0f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 225 additions and 73 deletions

View file

@ -371,42 +371,15 @@ void StreamLogOutput::logRaw(LogLevel lev, std::string_view line)
}
}
void LogOutputBuffer::updateLogLevel()
void StreamProxy::fix_stream_state(std::ostream &os)
{
const std::string &conf_loglev = g_settings->get("chat_log_level");
LogLevel log_level = Logger::stringToLevel(conf_loglev);
if (log_level == LL_MAX) {
warningstream << "Supplied unrecognized chat_log_level; "
"showing none." << std::endl;
log_level = LL_NONE;
}
m_logger.removeOutput(this);
m_logger.addOutputMaxLevel(this, log_level);
}
void LogOutputBuffer::logRaw(LogLevel lev, std::string_view line)
{
std::string color;
if (!g_settings->getBool("disable_escape_sequences")) {
switch (lev) {
case LL_ERROR: // red
color = "\x1b(c@#F00)";
break;
case LL_WARNING: // yellow
color = "\x1b(c@#EE0)";
break;
case LL_INFO: // grey
color = "\x1b(c@#BBB)";
break;
case LL_VERBOSE: // dark grey
case LL_TRACE:
color = "\x1b(c@#888)";
break;
default: break;
}
}
MutexAutoLock lock(m_buffer_mutex);
m_buffer.emplace(color.append(line));
std::ios::iostate state = os.rdstate();
// clear error state so the stream works again
os.clear();
if (state & std::ios::eofbit)
os << "(ostream:eofbit)";
if (state & std::ios::badbit)
os << "(ostream:badbit)";
if (state & std::ios::failbit)
os << "(ostream:failbit)";
}