This repository has been archived on 2023-09-09. You can view files and clone it, but cannot push or open issues/pull-requests.
skemla/lib/Logger.hpp

55 lines
1.1 KiB
C++
Raw Permalink Normal View History

2023-09-08 11:13:47 +00:00
#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