mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Relaxed Mutex of Logger. Attempt to optimize format function.
This commit is contained in:
parent
2012d53dd6
commit
cdad9f88b7
@ -230,13 +230,10 @@ std::string CLogFormatter::format(const LogRecord & record) const
|
||||
{
|
||||
std::string message = pattern;
|
||||
|
||||
// Format date
|
||||
dateStream.str(std::string());
|
||||
dateStream.clear();
|
||||
dateStream << record.timeStamp;
|
||||
boost::algorithm::replace_first(message, "%d", dateStream.str());
|
||||
//Format date
|
||||
boost::algorithm::replace_first(message, "%d", boost::posix_time::to_simple_string (record.timeStamp));
|
||||
|
||||
// Format log level
|
||||
//Format log level
|
||||
std::string level;
|
||||
switch(record.level)
|
||||
{
|
||||
@ -258,11 +255,13 @@ std::string CLogFormatter::format(const LogRecord & record) const
|
||||
}
|
||||
boost::algorithm::replace_first(message, "%l", level);
|
||||
|
||||
// Format name, thread id and message
|
||||
//Format name, thread id and 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, "%t", record.threadId);
|
||||
boost::algorithm::replace_first(message, "%m", record.message);
|
||||
|
||||
//return boost::to_string (boost::format("%d %d %d[%d] - %d") % dateStream.str() % level % record.domain.getName() % record.threadId % record.message);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
@ -365,8 +364,9 @@ CLogFileTarget::CLogFileTarget(boost::filesystem::path filePath, bool append /*=
|
||||
|
||||
void CLogFileTarget::write(const LogRecord & record)
|
||||
{
|
||||
std::string message = formatter.format(record); //formatting is slow, do it outside the lock
|
||||
TLockGuard _(mx);
|
||||
file << formatter.format(record) << std::endl;
|
||||
file << message << std::endl;
|
||||
}
|
||||
|
||||
const CLogFormatter & CLogFileTarget::getFormatter() const { return formatter; }
|
||||
|
@ -188,14 +188,17 @@ private:
|
||||
struct DLL_LINKAGE LogRecord
|
||||
{
|
||||
LogRecord(const CLoggerDomain & domain, ELogLevel::ELogLevel level, const std::string & message)
|
||||
: domain(domain), level(level), message(message), timeStamp(boost::posix_time::microsec_clock::local_time()),
|
||||
threadId(boost::this_thread::get_id()) { }
|
||||
: domain(domain),
|
||||
level(level),
|
||||
message(message),
|
||||
timeStamp(boost::posix_time::microsec_clock::local_time()),
|
||||
threadId(boost::lexical_cast<std::string>(boost::this_thread::get_id())) { }
|
||||
|
||||
CLoggerDomain domain;
|
||||
ELogLevel::ELogLevel level;
|
||||
std::string message;
|
||||
boost::posix_time::ptime timeStamp;
|
||||
boost::thread::id threadId;
|
||||
std::string threadId;
|
||||
};
|
||||
|
||||
/// The class CLogFormatter formats log records.
|
||||
|
Loading…
Reference in New Issue
Block a user