mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-14 00:55:20 +02:00
Use std::string_view in logging code
This commit is contained in:
25
src/log.cpp
25
src/log.cpp
@@ -55,7 +55,7 @@ public:
|
||||
return m_logger.hasOutput(m_level);
|
||||
}
|
||||
|
||||
virtual void log(const std::string &buf) override {
|
||||
virtual void log(std::string_view buf) override {
|
||||
if (!m_raw) {
|
||||
m_logger.log(m_level, buf);
|
||||
} else {
|
||||
@@ -106,7 +106,7 @@ thread_local LogStream dout_con(trace_target);
|
||||
// Android
|
||||
#ifdef __ANDROID__
|
||||
|
||||
static unsigned int g_level_to_android[] = {
|
||||
constexpr static unsigned int g_level_to_android[] = {
|
||||
ANDROID_LOG_INFO, // LL_NONE
|
||||
ANDROID_LOG_ERROR, // LL_ERROR
|
||||
ANDROID_LOG_WARN, // LL_WARNING
|
||||
@@ -116,11 +116,12 @@ static unsigned int g_level_to_android[] = {
|
||||
ANDROID_LOG_VERBOSE, // LL_TRACE
|
||||
};
|
||||
|
||||
void AndroidLogOutput::logRaw(LogLevel lev, const std::string &line)
|
||||
void AndroidLogOutput::logRaw(LogLevel lev, std::string_view line)
|
||||
{
|
||||
static_assert(ARRLEN(g_level_to_android) == LL_MAX,
|
||||
"mismatch between android and internal loglevels");
|
||||
__android_log_write(g_level_to_android[lev], PROJECT_NAME_C, line.c_str());
|
||||
__android_log_print(g_level_to_android[lev], PROJECT_NAME_C, "%.*s",
|
||||
line.size(), line.data());
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -131,7 +132,7 @@ void AndroidLogOutput::logRaw(LogLevel lev, const std::string &line)
|
||||
//// Logger
|
||||
////
|
||||
|
||||
LogLevel Logger::stringToLevel(const std::string &name)
|
||||
LogLevel Logger::stringToLevel(std::string_view name)
|
||||
{
|
||||
if (name == "none")
|
||||
return LL_NONE;
|
||||
@@ -202,7 +203,7 @@ void Logger::setLevelSilenced(LogLevel lev, bool silenced)
|
||||
m_silenced_levels[lev] = silenced;
|
||||
}
|
||||
|
||||
void Logger::registerThread(const std::string &name)
|
||||
void Logger::registerThread(std::string_view name)
|
||||
{
|
||||
std::thread::id id = std::this_thread::get_id();
|
||||
MutexAutoLock lock(m_mutex);
|
||||
@@ -252,7 +253,7 @@ const std::string &Logger::getThreadName()
|
||||
return fallback_name;
|
||||
}
|
||||
|
||||
void Logger::log(LogLevel lev, const std::string &text)
|
||||
void Logger::log(LogLevel lev, std::string_view text)
|
||||
{
|
||||
if (isLevelSilenced(lev))
|
||||
return;
|
||||
@@ -268,7 +269,7 @@ void Logger::log(LogLevel lev, const std::string &text)
|
||||
logToOutputs(lev, line, timestamp, thread_name, text);
|
||||
}
|
||||
|
||||
void Logger::logRaw(LogLevel lev, const std::string &text)
|
||||
void Logger::logRaw(LogLevel lev, std::string_view text)
|
||||
{
|
||||
if (isLevelSilenced(lev))
|
||||
return;
|
||||
@@ -276,7 +277,7 @@ void Logger::logRaw(LogLevel lev, const std::string &text)
|
||||
logToOutputsRaw(lev, text);
|
||||
}
|
||||
|
||||
void Logger::logToOutputsRaw(LogLevel lev, const std::string &line)
|
||||
void Logger::logToOutputsRaw(LogLevel lev, std::string_view line)
|
||||
{
|
||||
MutexAutoLock lock(m_mutex);
|
||||
for (size_t i = 0; i != m_outputs[lev].size(); i++)
|
||||
@@ -285,7 +286,7 @@ void Logger::logToOutputsRaw(LogLevel lev, const std::string &line)
|
||||
|
||||
void Logger::logToOutputs(LogLevel lev, const std::string &combined,
|
||||
const std::string &time, const std::string &thread_name,
|
||||
const std::string &payload_text)
|
||||
std::string_view payload_text)
|
||||
{
|
||||
MutexAutoLock lock(m_mutex);
|
||||
for (size_t i = 0; i != m_outputs[lev].size(); i++)
|
||||
@@ -334,7 +335,7 @@ StreamLogOutput::StreamLogOutput(std::ostream &stream) :
|
||||
#endif
|
||||
}
|
||||
|
||||
void StreamLogOutput::logRaw(LogLevel lev, const std::string &line)
|
||||
void StreamLogOutput::logRaw(LogLevel lev, std::string_view line)
|
||||
{
|
||||
bool colored_message = (Logger::color_mode == LOG_COLOR_ALWAYS) ||
|
||||
(Logger::color_mode == LOG_COLOR_AUTO && is_tty);
|
||||
@@ -385,7 +386,7 @@ void LogOutputBuffer::updateLogLevel()
|
||||
m_logger.addOutputMaxLevel(this, log_level);
|
||||
}
|
||||
|
||||
void LogOutputBuffer::logRaw(LogLevel lev, const std::string &line)
|
||||
void LogOutputBuffer::logRaw(LogLevel lev, std::string_view line)
|
||||
{
|
||||
std::string color;
|
||||
|
||||
|
Reference in New Issue
Block a user