mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-27 04:12:40 +01:00
Shared/Logs: Improve log performances
Improve Log::ShouldLog() performances by saving the lowest log level across all loggers and discarding any log with lower level than that.
This commit is contained in:
@@ -199,6 +199,9 @@ void Log::CreateLoggerFromConfig(std::string const& appenderName)
|
||||
return;
|
||||
}
|
||||
|
||||
if (level < lowestLogLevel)
|
||||
lowestLogLevel = level;
|
||||
|
||||
logger.Create(name, level);
|
||||
//fprintf(stdout, "Log::CreateLoggerFromConfig: Created Logger %s, Level %u\n", name.c_str(), level);
|
||||
|
||||
@@ -394,6 +397,7 @@ void Log::LoadFromConfig()
|
||||
{
|
||||
Close();
|
||||
|
||||
lowestLogLevel = LOG_LEVEL_FATAL;
|
||||
AppenderId = 0;
|
||||
m_logsDir = sConfigMgr->GetStringDefault("LogsDir", "");
|
||||
if (!m_logsDir.empty())
|
||||
|
||||
@@ -82,6 +82,7 @@ class Log
|
||||
AppenderMap appenders;
|
||||
LoggerMap loggers;
|
||||
uint8 AppenderId;
|
||||
LogLevel lowestLogLevel;
|
||||
|
||||
std::string m_logsDir;
|
||||
std::string m_logsTimestamp;
|
||||
@@ -113,6 +114,10 @@ inline bool Log::ShouldLog(std::string const& type, LogLevel level) const
|
||||
// Speed up in cases where requesting "Type.sub1.sub2" but only configured
|
||||
// Logger "Type"
|
||||
|
||||
// Don't even look for a logger if the LogLevel is lower than lowest log levels across all loggers
|
||||
if (level < lowestLogLevel)
|
||||
return false;
|
||||
|
||||
Logger const* logger = GetLoggerByType(type);
|
||||
if (!logger)
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user