fix exception messages

This commit is contained in:
chatlanin
2024-07-10 10:51:44 +03:00
parent 0b761bde2b
commit 767d859ea7

View File

@@ -5,9 +5,8 @@
#include "nlohmann/json.hpp"
#define DEF_LINE() std::to_string(std::experimental::source_location::current().line())
#define DEF_LOCATION() std::experimental::source_location::current().file_name() + std::string(" : ") + DEF_LINE()
#define DEF_FILE_NAME() std::experimental::source_location::current().file_name()
#define DEF_LINE() std::experimental::source_location::current().line()
#define DEF_LOCATION() std::experimental::source_location::current()
#include "hack/logger/logger.hpp"
#include "hack/utils/json_converter.hpp"
@@ -19,7 +18,7 @@ namespace hack
class exception : public utils::json_converter<JSON>
{
public:
exception(const std::string loc = DEF_LOCATION()) : m_location { loc } {}
exception(const std::experimental::source_location loc = DEF_LOCATION()) : m_location { loc } {}
~exception() = default;
public:
@@ -48,15 +47,17 @@ namespace hack
}
template<typename Database>
void commit(const std::filesystem::path file_name = DEF_FILE_NAME(), std::string line = DEF_LINE())
void commit()
{
Database::instance().execute("logger", convert_to_json());
}
void log(const std::filesystem::path file_name = DEF_FILE_NAME(), std::string line = DEF_LINE())
void log()
{
error("")(file_name,":", line, ": ", m_message);
warn("")(m_location, ": ", m_description);
error("", m_location)(m_message);
warn("", m_location)(m_description);
if (!m_system_error.empty())
warn("", m_location)("system_error: ", m_system_error);
}
private:
@@ -65,7 +66,7 @@ namespace hack
JSON j;
j["description"] = m_description;
j["system_error"] = m_system_error;
j["location"] = m_location;
j["location"] = m_location.file_name();
j["params"] = m_params;
j["msg_to_front"] = m_message;
@@ -76,7 +77,7 @@ namespace hack
std::string m_message { "no valid data" };
std::string m_description;
std::string m_system_error;
std::string m_location;
std::experimental::source_location m_location;
JSON m_params;
};
}