1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00
vcmi/include/vstd/CLoggerBase.h
Fay b5daa24982 Android support (#299)
* AI libs registering shenanigans on android;
* Fixed resolution aspect + mouse event scaling;
* Proper server init/deinit (through android IPC);
Enabled threaded init in CMT;
* Prevented a deadlock in logger on some devices;
* Fixed frozen intro frame after interrupting the video;
Added android progressbar displaying during initial data loading;
* Hacky fix for choppy animations during heroes movement (should look better now, but it's definitely not a good solution);
* Changes/fixes for new android launcher building process;
* Fixed app hang after getting SDL_QUIT when activity was destroyed;
* Functioanal, configurable advmap swiping support;
* VCMI changes cleanup;
Added few missing VCMI_ANDROID guards on swipe mechanics;
* Removed unneeded sleep in server startup code for android;
* Removed android ioapi hack (fixed in newest ndk);
* Removed unused android's library loading logic;
* Added android's swipe option to settings schema;
* Moved NO_STD_TOSTRING to be defined in global.h instead of build files;
2017-05-25 20:57:20 +03:00

140 lines
2.8 KiB
C++

/*
* CLoggerBase.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 ELogLevel
{
enum ELogLevel
{
NOT_SET = 0,
TRACE,
DEBUG,
INFO,
WARN,
ERROR
};
inline std::string to_string(ELogLevel level)
{
switch (level) {
case NOT_SET:
return "not set";
case TRACE:
return "trace";
case DEBUG:
return "debug";
case INFO:
return "info";
case WARN:
return "warn";
case ERROR:
return "error";
default:
#ifdef NO_STD_TOSTRING
return "invalid";
#else
return std::string("invalid (") + std::to_string(level) + ")";
#endif
}
}
}
namespace vstd
{
class DLL_LINKAGE CLoggerBase
{
public:
virtual ~CLoggerBase(){};
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>
void log(ELogLevel::ELogLevel level, const std::string & format, T t, Args ... args) const
{
boost::format fmt(format);
makeFormat(fmt, t, args...);
log(level, fmt);
}
/// Log methods for various log levels
inline void error(const std::string & message) const
{
log(ELogLevel::ERROR, message);
};
template<typename T, typename ... Args>
void error(const std::string & format, T t, Args ... args) const
{
log(ELogLevel::ERROR, format, t, args...);
}
inline void warn(const std::string & message) const
{
log(ELogLevel::WARN, message);
};
template<typename T, typename ... Args>
void warn(const std::string & format, T t, Args ... args) const
{
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) const
{
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) const
{
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) const
{
log(ELogLevel::TRACE, format, t, args...);
}
private:
template <typename T>
void makeFormat(boost::format & fmt, T t) const
{
fmt % t;
}
template <typename T, typename ... Args>
void makeFormat(boost::format & fmt, T t, Args ... args) const
{
fmt % t;
makeFormat(fmt, args...);
}
};
}