40 lines
703 B
C++
40 lines
703 B
C++
|
#ifndef jk_LOGGER_HPP
|
||
|
#define jk_LOGGER_HPP
|
||
|
|
||
|
#include "commons.hpp"
|
||
|
#include "Loc.hpp"
|
||
|
|
||
|
#define LOG_TYPE(G) \
|
||
|
G(LOG_ERROR)
|
||
|
|
||
|
namespace jk
|
||
|
{
|
||
|
JK_ENUM(Log, LOG_TYPE);
|
||
|
|
||
|
class Logger
|
||
|
{
|
||
|
public:
|
||
|
explicit Logger();
|
||
|
virtual ~Logger();
|
||
|
|
||
|
template<typename T>
|
||
|
void log(LogType type, Loc const& loc, std::string const& what);
|
||
|
|
||
|
private:
|
||
|
};
|
||
|
|
||
|
template<typename T>
|
||
|
void Logger::log(LogType type, Loc const& loc, std::string const& what)
|
||
|
{
|
||
|
std::stringstream ss;
|
||
|
ss << loc.path().string() << ":" << loc.line();
|
||
|
ss << " " << (std::string(LogTypeStr[type])
|
||
|
.substr(std::string("LOG_").size()));
|
||
|
ss << " " << what;
|
||
|
|
||
|
throw T { ss.str() };
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|