1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

Fixes excessive logging causing RMG slowdown

- Do not apply formatting on log entries that will be discarded due to
high log level
- Do not log incorrect access to visitablePos due to its numerous use by
RMG
This commit is contained in:
Ivan Savenko
2024-12-23 21:24:00 +00:00
parent 2272707175
commit 6da58a6871
4 changed files with 28 additions and 21 deletions

View File

@ -58,6 +58,7 @@ public:
virtual void log(ELogLevel::ELogLevel level, const std::string & message) const = 0;
virtual void log(ELogLevel::ELogLevel level, const boost::format & fmt) const = 0;
virtual ELogLevel::ELogLevel getEffectiveLevel() const = 0;
/// Returns true if a debug/trace log message will be logged, false if not.
/// Useful if performance is important and concatenating the log message is a expensive task.
@ -67,16 +68,19 @@ public:
template<typename T, typename ... Args>
void log(ELogLevel::ELogLevel level, const std::string & format, T t, Args ... args) const
{
try
if (getEffectiveLevel() <= level)
{
boost::format fmt(format);
makeFormat(fmt, t, args...);
log(level, fmt);
}
catch(...)
{
log(ELogLevel::ERROR, "Log formatting failed, format was:");
log(ELogLevel::ERROR, format);
try
{
boost::format fmt(format);
makeFormat(fmt, t, args...);
log(level, fmt);
}
catch(...)
{
log(ELogLevel::ERROR, "Log formatting failed, format was:");
log(ELogLevel::ERROR, format);
}
}
}