aboutsummaryrefslogtreecommitdiff
path: root/src/logging.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2025-01-11 16:45:15 +0000
committerGravatar Sadie Powell2025-01-11 16:51:34 +0000
commitc6238d80dee66bcefa92220a35d582ab739aa8a5 (patch)
tree180f082eda2b11986a0c9492ce6a63b3aceed11e /src/logging.cpp
parentSynchronise the snomask list with th list from the docs site. (diff)
Don't format log messages if we can't actually log them.
This should prevent debug messages from potentially causing performance issues on production servers.
Diffstat (limited to 'src/logging.cpp')
-rw-r--r--src/logging.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/logging.cpp b/src/logging.cpp
index 665939f9b..ebae62019 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -224,7 +224,7 @@ void Log::Manager::OpenLogs(bool requiremethods)
{
const auto* option = ServerInstance->Config->CommandLine.forceprotodebug ? "--protocoldebug" : "--debug";
Normal("LOG", "Not opening loggers because we were started with {}", option);
- CheckRawLog();
+ CheckLevel();
return;
}
@@ -232,7 +232,7 @@ void Log::Manager::OpenLogs(bool requiremethods)
if (!ServerInstance->Config->CommandLine.writelog)
{
Normal("LOG", "Not opening loggers because we were started with --nolog");
- CheckRawLog();
+ CheckLevel();
return;
}
@@ -297,7 +297,7 @@ void Log::Manager::OpenLogs(bool requiremethods)
cache.shrink_to_fit();
caching = false;
}
- CheckRawLog();
+ CheckLevel();
}
void Log::Manager::RegisterServices()
@@ -316,12 +316,20 @@ void Log::Manager::UnloadEngine(const Engine* engine)
Normal("LOG", "The {} log engine is unloading; removed {}/{} loggers.", engine->name.c_str(), logger_count - loggers.size(), logger_count);
}
-void Log::Manager::CheckRawLog()
+void Log::Manager::CheckLevel()
{
// There might be a logger not from the config so we need to check this outside of the creation loop.
- ServerInstance->Config->RawLog = std::any_of(loggers.begin(), loggers.end(), [](const auto& logger) {
- return logger.level >= Level::RAWIO;
- });
+ auto newmaxlevel = Level::LOWEST;
+ for (const auto& logger : loggers)
+ {
+ if (logger.level > newmaxlevel)
+ newmaxlevel = logger.level;
+ }
+
+ std::swap(maxlevel, newmaxlevel);
+ ServerInstance->Config->RawLog = (newmaxlevel >= Level::RAWIO);
+
+ Debug("LOG", "Changed maximum log level from {} to {}", LevelToString(newmaxlevel), LevelToString(maxlevel));
}
void Log::Manager::Write(Level level, const std::string& type, const std::string& message)
@@ -329,6 +337,9 @@ void Log::Manager::Write(Level level, const std::string& type, const std::string
if (logging)
return; // Avoid log loops.
+ if (maxlevel < level && !caching)
+ return; // No loggers care about this message.
+
logging = true;
time_t time = ServerInstance->Time();
for (auto& logger : loggers)