mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Moved boost:format log proxy to CLoggerBase
This commit is contained in:
parent
599f4cfb55
commit
74a82c4c9d
@ -32,30 +32,83 @@ namespace vstd
|
||||
|
||||
virtual void log(ELogLevel::ELogLevel level, const std::string & message) const = 0;
|
||||
|
||||
template<typename T, typename ... Args>
|
||||
void log(ELogLevel::ELogLevel level, const std::string & format, T t, Args ... args)
|
||||
{
|
||||
boost::format fmt(format);
|
||||
makeFormat(fmt, t, args...);
|
||||
log(level, fmt.str());
|
||||
}
|
||||
|
||||
/// Log methods for various log levels
|
||||
inline void trace(const std::string & message) const
|
||||
inline void error(const std::string & message) const
|
||||
{
|
||||
log(ELogLevel::TRACE, message);
|
||||
log(ELogLevel::ERROR, message);
|
||||
};
|
||||
|
||||
inline void debug(const std::string & message) const
|
||||
template<typename T, typename ... Args>
|
||||
void error(const std::string & format, T t, Args ... args)
|
||||
{
|
||||
log(ELogLevel::DEBUG, message);
|
||||
};
|
||||
|
||||
inline void info(const std::string & message) const
|
||||
{
|
||||
log(ELogLevel::INFO, message);
|
||||
};
|
||||
log(ELogLevel::ERROR, format, t, args...);
|
||||
}
|
||||
|
||||
inline void warn(const std::string & message) const
|
||||
{
|
||||
log(ELogLevel::WARN, message);
|
||||
};
|
||||
|
||||
inline void error(const std::string & message) const
|
||||
template<typename T, typename ... Args>
|
||||
void warn(const std::string & format, T t, Args ... args)
|
||||
{
|
||||
log(ELogLevel::ERROR, message);
|
||||
log(ELogLevel::WARN, format, t, args...);
|
||||
}
|
||||
|
||||
inline void info(const std::string & message) const
|
||||
{
|
||||
log(ELogLevel::INFO, message);
|
||||
};
|
||||
|
||||
template<typename T, typename ... Args>
|
||||
void info(const std::string & format, T t, Args ... args)
|
||||
{
|
||||
log(ELogLevel::INFO, format, t, args...);
|
||||
}
|
||||
|
||||
inline void debug(const std::string & message) const
|
||||
{
|
||||
log(ELogLevel::DEBUG, message);
|
||||
};
|
||||
|
||||
|
||||
template<typename T, typename ... Args>
|
||||
void debug(const std::string & format, T t, Args ... args)
|
||||
{
|
||||
log(ELogLevel::DEBUG, format, t, args...);
|
||||
}
|
||||
|
||||
inline void trace(const std::string & message) const
|
||||
{
|
||||
log(ELogLevel::TRACE, message);
|
||||
};
|
||||
|
||||
template<typename T, typename ... Args>
|
||||
void trace(const std::string & format, T t, Args ... args)
|
||||
{
|
||||
log(ELogLevel::TRACE, format, t, args...);
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
void makeFormat(boost::format & fmt, T t)
|
||||
{
|
||||
fmt % t;
|
||||
}
|
||||
|
||||
template <typename T, typename ... Args>
|
||||
void makeFormat(boost::format & fmt, T t, Args ... args)
|
||||
{
|
||||
fmt % t;
|
||||
makeFormat(fmt, args...);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* CLogFormat.h, part of VCMI engine
|
||||
*
|
||||
* Authors: listed in file AUTHORS in main folder
|
||||
*
|
||||
* License: GNU General Public License v2.0 or later
|
||||
* Full text of license available in license.txt file, in main folder
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace vstd
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template <typename T>
|
||||
void makeFormat(boost::format & fmt, T t)
|
||||
{
|
||||
fmt % t;
|
||||
}
|
||||
|
||||
template <typename T, typename ... Args>
|
||||
void makeFormat(boost::format & fmt, T t, Args ... args)
|
||||
{
|
||||
fmt % t;
|
||||
makeFormat(fmt, args...);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Put into CLogger after log api extract
|
||||
|
||||
template<typename Logger>
|
||||
void log(Logger * logger, ELogLevel::ELogLevel level, const std::string & message)
|
||||
{
|
||||
logger->log(level, message);
|
||||
}
|
||||
|
||||
template<typename Logger, typename T, typename ... Args>
|
||||
void log(Logger * logger, ELogLevel::ELogLevel level, const std::string & format, T t, Args ... args)
|
||||
{
|
||||
boost::format fmt(format);
|
||||
detail::makeFormat(fmt, t, args...);
|
||||
logger->log(level, fmt.str());
|
||||
}
|
||||
|
||||
template<typename Logger, typename T, typename ... Args>
|
||||
void logError(Logger * logger, const std::string & format, T t, Args ... args)
|
||||
{
|
||||
log(logger, ELogLevel::ERROR, format, t, args...);
|
||||
}
|
||||
|
||||
template<typename Logger, typename T, typename ... Args>
|
||||
void logWarn(Logger * logger, const std::string & format, T t, Args ... args)
|
||||
{
|
||||
log(logger, ELogLevel::WARN, format, t, args...);
|
||||
}
|
||||
|
||||
template<typename Logger, typename T, typename ... Args>
|
||||
void logInfo(Logger * logger, const std::string & format, T t, Args ... args)
|
||||
{
|
||||
log(logger, ELogLevel::INFO, format, t, args...);
|
||||
}
|
||||
|
||||
template<typename Logger, typename T, typename ... Args>
|
||||
void logDebug(Logger * logger, const std::string & format, T t, Args ... args)
|
||||
{
|
||||
log(logger, ELogLevel::DEBUG, format, t, args...);
|
||||
}
|
||||
|
||||
template<typename Logger, typename T, typename ... Args>
|
||||
void logTrace(Logger * logger, const std::string & format, T t, Args ... args)
|
||||
{
|
||||
log(logger, ELogLevel::TRACE, format, t, args...);
|
||||
}
|
||||
}
|
@ -78,14 +78,14 @@ const PlayerState * CGameInfoCallback::getPlayer(PlayerColor color, bool verbose
|
||||
else
|
||||
{
|
||||
if (verbose)
|
||||
vstd::logError(logGlobal, "Cannot access player %d info!", color);
|
||||
logGlobal->error("Cannot access player %d info!", color);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (verbose)
|
||||
vstd::logError(logGlobal, "Cannot find player %d info!", color);
|
||||
logGlobal->error("Cannot find player %d info!", color);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@ -842,7 +842,7 @@ const TeamState * CGameInfoCallback::getTeam( TeamID teamID ) const
|
||||
}
|
||||
else
|
||||
{
|
||||
vstd::logError(logGlobal, "Cannot find info for team %d", teamID);
|
||||
logGlobal->error("Cannot find info for team %d", teamID);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,6 @@
|
||||
|
||||
#include "../Global.h"
|
||||
|
||||
//todo: move to Global.h
|
||||
#include <vstd/LogFormat.h>
|
||||
|
||||
// This header should be treated as a pre compiled header file(PCH) in the compiler building settings.
|
||||
|
||||
// Here you can add specific libraries and macros which are specific to this project.
|
||||
|
@ -122,7 +122,6 @@
|
||||
</Linker>
|
||||
<Unit filename="../Global.h" />
|
||||
<Unit filename="../include/vstd/CLoggerBase.h" />
|
||||
<Unit filename="../include/vstd/LogFormat.h" />
|
||||
<Unit filename="AI_Base.h" />
|
||||
<Unit filename="BattleAction.cpp" />
|
||||
<Unit filename="BattleAction.h" />
|
||||
|
@ -129,7 +129,7 @@ const CSpell::LevelInfo & CSpell::getLevelInfo(const int level) const
|
||||
{
|
||||
if(level < 0 || level >= GameConstants::SPELL_SCHOOL_LEVELS)
|
||||
{
|
||||
vstd::logError(logGlobal, "CSpell::getLevelInfo invalid school level %d", level);
|
||||
logGlobal->error("CSpell::getLevelInfo invalid school level %d", level);
|
||||
throw new std::runtime_error("Invalid school level");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user