From d6178d0bb5799ec1fcc310608cabf1396d67f34c Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Fri, 12 Aug 2016 11:17:15 +0300 Subject: [PATCH] Implemented boost::format based log proxy. --- include/vstd/LogFormat.h | 48 ++++++++++++++++++++++++++++++++++++ lib/logging/CLogger.h | 2 +- lib/spells/CSpellHandler.cpp | 2 +- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/include/vstd/LogFormat.h b/include/vstd/LogFormat.h index 487fbd504..802818a0b 100644 --- a/include/vstd/LogFormat.h +++ b/include/vstd/LogFormat.h @@ -12,9 +12,57 @@ namespace vstd { + namespace detail + { + template + void makeFormat(boost::format & fmt, T t) + { + fmt % t; + } + + template + void makeFormat(boost::format & fmt, T t, Args ... args) + { + fmt % t; + makeFormat(fmt, args...); + } + } + + template + void logFormat(Logger * logger, ELogLevel::ELogLevel level, const std::string & format, Args ... args) + { + boost::format fmt(format); + detail::makeFormat(fmt, args...); + logger->log(level, fmt.str()); + } + + template + void logErrorFormat(Logger * logger, const std::string & format, Args ... args) + { + logFormat(logger, ELogLevel::ERROR, format, args...); + } + + template + void logWarnFormat(Logger * logger, const std::string & format, Args ... args) + { + logFormat(logger, ELogLevel::WARN, format, args...); + } + + template + void logInfoFormat(Logger * logger, const std::string & format, Args ... args) + { + logFormat(logger, ELogLevel::INFO, format, args...); + } + template void logDebugFormat(Logger * logger, const std::string & format, Args ... args) { + logFormat(logger, ELogLevel::DEBUG, format, args...); + } + template + void logTraceFormat(Logger * logger, const std::string & format, Args ... args) + { + logFormat(logger, ELogLevel::TRACE, format, args...); } } diff --git a/lib/logging/CLogger.h b/lib/logging/CLogger.h index 2318cf4f3..66b9e825d 100644 --- a/lib/logging/CLogger.h +++ b/lib/logging/CLogger.h @@ -104,7 +104,7 @@ public: CLoggerStream warnStream() const; CLoggerStream errorStream() const; - inline void log(ELogLevel::ELogLevel level, const std::string & message) const; + void log(ELogLevel::ELogLevel level, const std::string & message) const; void addTarget(std::unique_ptr && target); void clearTargets(); diff --git a/lib/spells/CSpellHandler.cpp b/lib/spells/CSpellHandler.cpp index 090f1fb0d..7860bbdd6 100644 --- a/lib/spells/CSpellHandler.cpp +++ b/lib/spells/CSpellHandler.cpp @@ -129,7 +129,7 @@ const CSpell::LevelInfo & CSpell::getLevelInfo(const int level) const { if(level < 0 || level >= GameConstants::SPELL_SCHOOL_LEVELS) { - logGlobal->errorStream() << __FUNCTION__ << " invalid school level " << level; + vstd::logErrorFormat(logGlobal, "CSpell::getLevelInfo invalid school level %d", level); throw new std::runtime_error("Invalid school level"); }