55 lines
1.1 KiB
C++
55 lines
1.1 KiB
C++
|
#ifndef sk_LOGGER_HPP
|
||
|
#define sk_LOGGER_HPP
|
||
|
|
||
|
#include "commons.hpp"
|
||
|
|
||
|
#include "Loc.hpp"
|
||
|
|
||
|
#define LOGGER_TYPE(G) \
|
||
|
G(LOGGER_ERROR)
|
||
|
|
||
|
namespace sk
|
||
|
{
|
||
|
SK_ENUM(Logger, LOGGER_TYPE);
|
||
|
|
||
|
class Logger
|
||
|
{
|
||
|
public:
|
||
|
explicit Logger();
|
||
|
virtual ~Logger();
|
||
|
|
||
|
template<typename T>
|
||
|
void log(Loc loc, LoggerType type, std::stringstream const& what);
|
||
|
|
||
|
template<typename T>
|
||
|
void log(Loc loc, LoggerType type, std::string const& what);
|
||
|
private:
|
||
|
};
|
||
|
|
||
|
template<typename T>
|
||
|
void Logger::log(Loc loc, LoggerType type, std::stringstream const& what)
|
||
|
{
|
||
|
log<T>(loc, type, what.str());
|
||
|
}
|
||
|
|
||
|
template<typename T>
|
||
|
void Logger::log(Loc loc, LoggerType type, std::string const& what)
|
||
|
{
|
||
|
std::string type_str = std::string(LoggerTypeStr[type])
|
||
|
.substr(std::string("LOGGER_").size());
|
||
|
std::stringstream msg;
|
||
|
|
||
|
switch (type)
|
||
|
{
|
||
|
case LOGGER_ERROR: {
|
||
|
msg << loc.path().string() << ":" << loc.line();
|
||
|
msg << " " << type_str << " " << what;
|
||
|
throw T {msg.str()};
|
||
|
} break;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|