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:
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user