1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Fixed CID 1197474, CID 1366358

This commit is contained in:
AlexVinS 2016-11-28 19:34:20 +03:00
parent 394d6e0677
commit 36598d8695
5 changed files with 17 additions and 1 deletions

View File

@ -51,13 +51,14 @@ namespace vstd
virtual ~CLoggerBase(){}; virtual ~CLoggerBase(){};
virtual void log(ELogLevel::ELogLevel level, const std::string & message) const = 0; virtual void log(ELogLevel::ELogLevel level, const std::string & message) const = 0;
virtual void log(ELogLevel::ELogLevel level, const boost::format & fmt) const = 0;
template<typename T, typename ... Args> template<typename T, typename ... Args>
void log(ELogLevel::ELogLevel level, const std::string & format, T t, Args ... args) const void log(ELogLevel::ELogLevel level, const std::string & format, T t, Args ... args) const
{ {
boost::format fmt(format); boost::format fmt(format);
makeFormat(fmt, t, args...); makeFormat(fmt, t, args...);
log(level, fmt.str()); log(level, fmt);
} }
/// Log methods for various log levels /// Log methods for various log levels

View File

@ -153,6 +153,7 @@
<Unit filename="CGameInterface.h" /> <Unit filename="CGameInterface.h" />
<Unit filename="CGameState.cpp" /> <Unit filename="CGameState.cpp" />
<Unit filename="CGameState.h" /> <Unit filename="CGameState.h" />
<Unit filename="CGameStateFwd.h" />
<Unit filename="CGeneralTextHandler.cpp" /> <Unit filename="CGeneralTextHandler.cpp" />
<Unit filename="CGeneralTextHandler.h" /> <Unit filename="CGeneralTextHandler.h" />
<Unit filename="CHeroHandler.cpp" /> <Unit filename="CHeroHandler.cpp" />

View File

@ -119,6 +119,18 @@ void CLogger::log(ELogLevel::ELogLevel level, const std::string & message) const
callTargets(LogRecord(domain, level, message)); callTargets(LogRecord(domain, level, message));
} }
void CLogger::log(ELogLevel::ELogLevel level, const boost::format & fmt) const
{
try
{
log(level, fmt.str());
}
catch(...)
{
log(ELogLevel::ERROR, "Invalid log format!");
}
}
ELogLevel::ELogLevel CLogger::getLevel() const ELogLevel::ELogLevel CLogger::getLevel() const
{ {
TLockGuard _(mx); TLockGuard _(mx);

View File

@ -89,6 +89,7 @@ public:
CLoggerStream errorStream() const; CLoggerStream errorStream() const;
void log(ELogLevel::ELogLevel level, const std::string & message) const override; void log(ELogLevel::ELogLevel level, const std::string & message) const override;
void log(ELogLevel::ELogLevel level, const boost::format & fmt) const override;
void addTarget(std::unique_ptr<ILogTarget> && target); void addTarget(std::unique_ptr<ILogTarget> && target);
void clearTargets(); void clearTargets();

View File

@ -71,6 +71,7 @@
</Unit> </Unit>
<Unit filename="StdInc.h"> <Unit filename="StdInc.h">
<Option compile="1" /> <Option compile="1" />
<Option weight="0" />
</Unit> </Unit>
<Extensions> <Extensions>
<code_completion /> <code_completion />