Using spdlog for logs

This commit is contained in:
Pcornat 2024-10-29 22:50:42 +01:00
parent 9515077e1e
commit 33ba0995fd
Signed by: Pcornat
GPG Key ID: E0326CC678A00BDD

View File

@ -1,8 +1,8 @@
#include "app_win_2_back.hpp"
#include "hello_world.hpp"
#include <iostream>
#include <glibmm/miscutils.h>
#include <gtkmm/switch.h>
#include <spdlog/spdlog.h>
namespace gui_to_app {
AppWin2Back::AppWin2Back() : Gtk::Application("org.billy_adventures.character_sheet", Flags::HANDLES_OPEN) {
@ -16,12 +16,12 @@ namespace gui_to_app {
const auto builder = Gtk::Builder::create_from_file("menu_bar.ui");
return builder->get_object<Gio::Menu>("menu");
} catch (const std::exception &e) {
std::cerr << e.what() << '\n';
spdlog::error("Error occurred while loader menu bar: {}", e.what());
return nullptr;
}
}();
if (!menu_bar) {
std::cerr << "Error occured while loading menu bar's.\n";
spdlog::error("Error occured while loading menu bar's.");
} else {
set_menubar(menu_bar);
add_action("quit", sigc::mem_fun(*this, &AppWin2Back::on_quit));
@ -40,13 +40,13 @@ namespace gui_to_app {
try {
return Gtk::Builder::create_from_file("window_ui.ui");
} catch (const std::exception &e) {
std::cerr << e.what() << std::endl;
spdlog::critical("Error occurred while loading Window's UI: {}", e.what());
quit();
return nullptr;
}
}();
if (!app_builder) {
std::cerr << "Error while loading UI.\n";
spdlog::critical("Error while loading UI");
quit();
return;
}
@ -56,6 +56,7 @@ namespace gui_to_app {
main_window->set_show_menubar(true);
main_window->set_visible(true);
} else {
spdlog::critical("Error while getting window from builder");
on_quit();
return;
}
@ -97,9 +98,9 @@ namespace gui_to_app {
return test_result;
}();
if (!test_result.empty()) {
std::cerr << "Error occurred, at least one switch is not available:\n";
spdlog::critical("Error occurred, at least one switch is not available. See logs below");
for (const auto result: test_result) {
std::cerr << result << '\n';
spdlog::critical(result);
}
on_quit();
return;