refactor
This commit is contained in:
parent
6348999295
commit
2dc6a30c4e
@ -47,115 +47,6 @@ static constexpr const std::uint64_t MAX_LOG_FILE_SIZE{
|
|||||||
1024ULL * 1024ULL * 5ULL,
|
1024ULL * 1024ULL * 5ULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct monitarr_exception_handler final
|
|
||||||
: public utils::error::i_exception_handler {
|
|
||||||
void handle_debug(std::string_view function_name,
|
|
||||||
std::string_view msg) const override {
|
|
||||||
spdlog::get("console")->debug(
|
|
||||||
utils::error::create_error_message(function_name, {msg}));
|
|
||||||
|
|
||||||
auto file = spdlog::get("file");
|
|
||||||
if (not file) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
file->debug(utils::error::create_error_message(function_name, {msg}));
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_error(std::string_view function_name,
|
|
||||||
std::string_view msg) const override {
|
|
||||||
spdlog::get("console")->error(
|
|
||||||
utils::error::create_error_message(function_name, {msg}));
|
|
||||||
|
|
||||||
auto file = spdlog::get("file");
|
|
||||||
if (not file) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
file->error(utils::error::create_error_message(function_name, {msg}));
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_exception(std::string_view function_name) const override {
|
|
||||||
spdlog::get("console")->error(utils::error::create_error_message(
|
|
||||||
function_name, {
|
|
||||||
"exception",
|
|
||||||
"unknown exception",
|
|
||||||
}));
|
|
||||||
|
|
||||||
auto file = spdlog::get("file");
|
|
||||||
if (not file) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
file->error(utils::error::create_error_message(function_name,
|
|
||||||
{
|
|
||||||
"exception",
|
|
||||||
"unknown exception",
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_exception(std::string_view function_name,
|
|
||||||
const std::exception &ex) const override {
|
|
||||||
spdlog::get("console")->error(utils::error::create_error_message(
|
|
||||||
function_name, {
|
|
||||||
"exception",
|
|
||||||
(ex.what() == nullptr ? "unknown" : ex.what()),
|
|
||||||
}));
|
|
||||||
|
|
||||||
auto file = spdlog::get("file");
|
|
||||||
if (not file) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
file->error(utils::error::create_error_message(
|
|
||||||
function_name, {
|
|
||||||
"exception",
|
|
||||||
(ex.what() == nullptr ? "unknown" : ex.what()),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_info(std::string_view function_name,
|
|
||||||
std::string_view msg) const override {
|
|
||||||
spdlog::get("console")->info(
|
|
||||||
utils::error::create_error_message(function_name, {msg}));
|
|
||||||
|
|
||||||
auto file = spdlog::get("file");
|
|
||||||
if (not file) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
file->info(utils::error::create_error_message(function_name, {msg}));
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_trace(std::string_view function_name,
|
|
||||||
std::string_view msg) const override {
|
|
||||||
spdlog::get("console")->trace(
|
|
||||||
utils::error::create_error_message(function_name, {msg}));
|
|
||||||
|
|
||||||
auto file = spdlog::get("file");
|
|
||||||
if (not file) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
file->trace(utils::error::create_error_message(function_name, {msg}));
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_warn(std::string_view function_name,
|
|
||||||
std::string_view msg) const override {
|
|
||||||
spdlog::get("console")->warn(
|
|
||||||
utils::error::create_error_message(function_name, {msg}));
|
|
||||||
|
|
||||||
auto file = spdlog::get("file");
|
|
||||||
if (not file) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
file->warn(utils::error::create_error_message(function_name, {msg}));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static const monitarr_exception_handler handler{};
|
|
||||||
|
|
||||||
auto main(int argc, char **argv) -> int {
|
auto main(int argc, char **argv) -> int {
|
||||||
MONITARR_USES_FUNCTION_NAME();
|
MONITARR_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
@ -187,7 +78,6 @@ auto main(int argc, char **argv) -> int {
|
|||||||
|
|
||||||
spdlog::drop("console");
|
spdlog::drop("console");
|
||||||
auto console = spdlog::stdout_color_mt("console");
|
auto console = spdlog::stdout_color_mt("console");
|
||||||
utils::error::set_exception_handler(&handler);
|
|
||||||
|
|
||||||
auto ret{0};
|
auto ret{0};
|
||||||
|
|
||||||
|
117
monitarr/monitarr/src/error_handler.cpp
Normal file
117
monitarr/monitarr/src/error_handler.cpp
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
#include "utils/config.hpp"
|
||||||
|
#include "utils/error.hpp"
|
||||||
|
|
||||||
|
namespace monitarr {
|
||||||
|
struct monitarr_exception_handler final
|
||||||
|
: public utils::error::i_exception_handler {
|
||||||
|
void handle_debug(std::string_view function_name,
|
||||||
|
std::string_view msg) const override {
|
||||||
|
spdlog::get("console")->debug(
|
||||||
|
utils::error::create_error_message(function_name, {msg}));
|
||||||
|
|
||||||
|
auto file = spdlog::get("file");
|
||||||
|
if (not file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
file->debug(utils::error::create_error_message(function_name, {msg}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_error(std::string_view function_name,
|
||||||
|
std::string_view msg) const override {
|
||||||
|
spdlog::get("console")->error(
|
||||||
|
utils::error::create_error_message(function_name, {msg}));
|
||||||
|
|
||||||
|
auto file = spdlog::get("file");
|
||||||
|
if (not file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
file->error(utils::error::create_error_message(function_name, {msg}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_exception(std::string_view function_name) const override {
|
||||||
|
spdlog::get("console")->error(utils::error::create_error_message(
|
||||||
|
function_name, {
|
||||||
|
"exception",
|
||||||
|
"unknown exception",
|
||||||
|
}));
|
||||||
|
|
||||||
|
auto file = spdlog::get("file");
|
||||||
|
if (not file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
file->error(utils::error::create_error_message(function_name,
|
||||||
|
{
|
||||||
|
"exception",
|
||||||
|
"unknown exception",
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_exception(std::string_view function_name,
|
||||||
|
const std::exception &ex) const override {
|
||||||
|
spdlog::get("console")->error(utils::error::create_error_message(
|
||||||
|
function_name, {
|
||||||
|
"exception",
|
||||||
|
(ex.what() == nullptr ? "unknown" : ex.what()),
|
||||||
|
}));
|
||||||
|
|
||||||
|
auto file = spdlog::get("file");
|
||||||
|
if (not file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
file->error(utils::error::create_error_message(
|
||||||
|
function_name, {
|
||||||
|
"exception",
|
||||||
|
(ex.what() == nullptr ? "unknown" : ex.what()),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_info(std::string_view function_name,
|
||||||
|
std::string_view msg) const override {
|
||||||
|
spdlog::get("console")->info(
|
||||||
|
utils::error::create_error_message(function_name, {msg}));
|
||||||
|
|
||||||
|
auto file = spdlog::get("file");
|
||||||
|
if (not file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
file->info(utils::error::create_error_message(function_name, {msg}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_trace(std::string_view function_name,
|
||||||
|
std::string_view msg) const override {
|
||||||
|
spdlog::get("console")->trace(
|
||||||
|
utils::error::create_error_message(function_name, {msg}));
|
||||||
|
|
||||||
|
auto file = spdlog::get("file");
|
||||||
|
if (not file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
file->trace(utils::error::create_error_message(function_name, {msg}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_warn(std::string_view function_name,
|
||||||
|
std::string_view msg) const override {
|
||||||
|
spdlog::get("console")->warn(
|
||||||
|
utils::error::create_error_message(function_name, {msg}));
|
||||||
|
|
||||||
|
auto file = spdlog::get("file");
|
||||||
|
if (not file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
file->warn(utils::error::create_error_message(function_name, {msg}));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static const auto handler = ([]() {
|
||||||
|
auto ptr = std::make_unique<monitarr_exception_handler>();
|
||||||
|
utils::error::set_exception_handler(ptr.get());
|
||||||
|
return ptr;
|
||||||
|
})();
|
||||||
|
} // namespace monitarr
|
Loading…
x
Reference in New Issue
Block a user