2023-09-10 23:05:29 +00:00
|
|
|
#ifndef grino_LOGGER_HPP
|
|
|
|
#define grino_LOGGER_HPP
|
|
|
|
|
|
|
|
#include "commons.hpp"
|
|
|
|
#include "src/mutils.hpp"
|
|
|
|
#include "Loc.hpp"
|
|
|
|
|
2023-09-11 11:46:41 +00:00
|
|
|
#define LOG_TYPE(G) \
|
|
|
|
G(LOG_ERROR), \
|
|
|
|
G(LOG_ASSERT),
|
|
|
|
|
2023-09-10 23:05:29 +00:00
|
|
|
|
|
|
|
namespace grino
|
|
|
|
{
|
|
|
|
GRINO_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 << "[" << GRINO_TRIM(LogTypeStr[type], "LOG_") << "] ";
|
|
|
|
ss << what;
|
|
|
|
|
|
|
|
throw T { ss.str() };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|