1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

- Some performance improvements for logging

This commit is contained in:
beegee1 2014-04-01 19:46:47 +00:00
parent 30b79588db
commit 48e7b7d805
2 changed files with 24 additions and 9 deletions

View File

@ -272,7 +272,8 @@ CLogger * CLogManager::getLogger(const CLoggerDomain & domain)
CLogFormatter::CLogFormatter() : pattern("%m")
{
boost::posix_time::time_facet * facet = new boost::posix_time::time_facet("%H:%M:%S");
dateStream.imbue(std::locale(dateStream.getloc(), facet));
}
CLogFormatter::CLogFormatter(const std::string & pattern)
@ -280,16 +281,26 @@ CLogFormatter::CLogFormatter(const std::string & pattern)
setPattern(pattern);
}
CLogFormatter::CLogFormatter(const CLogFormatter & other)
{
*this = other;
}
CLogFormatter & CLogFormatter::operator=(const CLogFormatter & other)
{
pattern = other.pattern;
return *this;
}
std::string CLogFormatter::format(const LogRecord & record) const
{
std::string message = pattern;
// Format date
std::stringstream dateStream;
boost::posix_time::time_facet * facet = new boost::posix_time::time_facet("%H:%M:%S");
dateStream.imbue(std::locale(dateStream.getloc(), facet));
dateStream.str(std::string());
dateStream.clear();
dateStream << record.timeStamp;
boost::algorithm::replace_all(message, "%d", dateStream.str());
boost::algorithm::replace_first(message, "%d", dateStream.str());
// Format log level
std::string level;
@ -311,12 +322,12 @@ std::string CLogFormatter::format(const LogRecord & record) const
level = "ERROR";
break;
}
boost::algorithm::replace_all(message, "%l", level);
boost::algorithm::replace_first(message, "%l", level);
// Format name, thread id and message
boost::algorithm::replace_all(message, "%n", record.domain.getName());
boost::algorithm::replace_all(message, "%t", boost::lexical_cast<std::string>(record.threadId));
boost::algorithm::replace_all(message, "%m", record.message);
boost::algorithm::replace_first(message, "%n", record.domain.getName());
boost::algorithm::replace_first(message, "%t", boost::lexical_cast<std::string>(record.threadId));
boost::algorithm::replace_first(message, "%m", record.message);
return message;
}

View File

@ -210,6 +210,9 @@ public:
CLogFormatter();
CLogFormatter(const std::string & pattern);
CLogFormatter(const CLogFormatter & other);
CLogFormatter & operator=(const CLogFormatter & other);
void setPattern(const std::string & pattern);
const std::string & getPattern() const;
@ -217,6 +220,7 @@ public:
private:
std::string pattern;
mutable std::stringstream dateStream;
};
/// The interface ILogTarget is used by all log target implementations. It holds