logger business

This commit is contained in:
m-aXimilian
2025-06-14 16:39:39 +02:00
committed by Kueffner, Maximilian
parent 566dd112ff
commit 25b0ef0ff5
4 changed files with 50 additions and 19 deletions
+10 -1
View File
@@ -4,6 +4,7 @@
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <spdlog/sinks/basic_file_sink.h> #include <spdlog/sinks/basic_file_sink.h>
#include <memory> #include <memory>
#include <sstream>
#include <string> #include <string>
#include "ILog.hpp" #include "ILog.hpp"
@@ -34,29 +35,37 @@ void SpdLogger::Error(const std::string& msg) { this->logger_->error(msg); }
void SpdLogger::ChangeLevel(LogLevel lvl) void SpdLogger::ChangeLevel(LogLevel lvl)
{ {
std::stringstream st{};
st << std::format("with argument {}", static_cast<int>(lvl));
switch (lvl) switch (lvl)
{ {
case LogLevel::Trace: case LogLevel::Trace:
this->logger_->set_level(spdlog::level::trace); this->logger_->set_level(spdlog::level::trace);
spdlog::flush_on(spdlog::level::trace); spdlog::flush_on(spdlog::level::trace);
st << "Trace";
break; break;
case LogLevel::Info: case LogLevel::Info:
this->logger_->set_level(spdlog::level::info); this->logger_->set_level(spdlog::level::info);
spdlog::flush_on(spdlog::level::info); spdlog::flush_on(spdlog::level::info);
st << "Info";
break; break;
case LogLevel::Warn: case LogLevel::Warn:
this->logger_->set_level(spdlog::level::warn); this->logger_->set_level(spdlog::level::warn);
spdlog::flush_on(spdlog::level::warn); spdlog::flush_on(spdlog::level::warn);
st << "Warn";
break; break;
case LogLevel::Error: case LogLevel::Error:
this->logger_->set_level(spdlog::level::err); this->logger_->set_level(spdlog::level::err);
spdlog::flush_on(spdlog::level::err); spdlog::flush_on(spdlog::level::err);
st << "Error";
break; break;
case LogLevel::Debug: case LogLevel::Debug:
default: default:
this->logger_->set_level(spdlog::level::debug); this->logger_->set_level(spdlog::level::debug);
spdlog::flush_on(spdlog::level::debug); spdlog::flush_on(spdlog::level::debug);
st << "Debug";
} }
this->logger_->debug("Changed log level;"); // you will only get this message for log levels <= info! I.e., not for error or warning.
this->logger_->info(std::format("{}: Changed log level {}", __FUNCTION__, st.str()).c_str());
} }
+22 -5
View File
@@ -10,6 +10,7 @@
#include "portable-file-dialogs.h" #include "portable-file-dialogs.h"
#include "rendering/CvMatRender.hpp" #include "rendering/CvMatRender.hpp"
#include "uiresources.h" #include "uiresources.h"
#include "utilities/ILog.hpp"
using namespace pixelarium::imaging; using namespace pixelarium::imaging;
@@ -134,7 +135,8 @@ int pixelarium::ui::AppGLFW::Run()
ImGui::DockSpaceOverViewport(ImGui::GetID("Backspace")); ImGui::DockSpaceOverViewport(ImGui::GetID("Backspace"));
this->MenuBar(); this->MenuBar();
if (demop_)
ImGui::ShowDemoWindow(&this->demop_);
if (this->imagep_) if (this->imagep_)
{ {
// auto render = render::CvMatRender(this->_img); // auto render = render::CvMatRender(this->_img);
@@ -200,6 +202,24 @@ void pixelarium::ui::AppGLFW::MenuBar()
// main menu // main menu
if (ImGui::BeginMenu(MAINMENUNAME)) if (ImGui::BeginMenu(MAINMENUNAME))
{ {
if (ImGui::BeginCombo(LOGLEVELSELECT, LOGLEVELS[log_level_]))
{
for (int n = 0; n < IM_ARRAYSIZE(LOGLEVELS); n++)
{
bool is_selected = (LOGLEVELS[log_level_] == LOGLEVELS[n]);
if (ImGui::Selectable(LOGLEVELS[n], is_selected))
{
log_level_ = n;
this->logger_.ChangeLevel(static_cast<utils::log::LogLevel>(1 << log_level_));
}
if (is_selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
ImGui::MenuItem(SHOWIMGUIDEMOS, NULL, &this->demop_);
ImGui::EndMenu(); ImGui::EndMenu();
} }
@@ -223,10 +243,7 @@ void pixelarium::ui::AppGLFW::LoadImageProt()
auto res{pfd::open_file("Load Inputs", pfd::path::home(), {"All Files", "*"}, pfd::opt::multiselect).result()}; auto res{pfd::open_file("Load Inputs", pfd::path::home(), {"All Files", "*"}, pfd::opt::multiselect).result()};
for (auto& p : res) for (auto& p : res)
{ {
if (this->logger_) this->logger_.Debug(std::format("{}: Creating image {}", __FUNCTION__, p));
{
this->logger_->Debug(std::format("{}: Creating image {}", __FUNCTION__, p));
}
this->img_ = std::make_shared<PixelariumImage>(p); this->img_ = std::make_shared<PixelariumImage>(p);
this->render_ = pixelarium::render::CvMatRender(this->img_); this->render_ = pixelarium::render::CvMatRender(this->img_);
+10 -11
View File
@@ -29,19 +29,16 @@ enum LogLevelSelection
class AppGLFW class AppGLFW
{ {
public: public:
AppGLFW() { this->InitMainWindow(); } explicit AppGLFW(std::unique_ptr<utils::log::ILog>& log) : logger_(*log)
AppGLFW(std::unique_ptr<utils::log::ILog>& log) : AppGLFW()
{ {
logger_ = log.get(); logger_.Debug(std::format("{}: Initiating a new window", __FUNCTION__).c_str());
if (logger_)
{
logger_->Debug(std::format("{}: Initiating a new window", __FUNCTION__).c_str());
if (pool_) if (pool_)
{ {
logger_->Debug(std::format("{}: We have an image resource pool!", __FUNCTION__).c_str()); logger_.Debug(std::format("{}: We have an image resource pool!", __FUNCTION__).c_str());
}
} }
this->InitMainWindow();
} }
AppGLFW(std::unique_ptr<utils::log::ILog>& log, std::unique_ptr<pixelarium::resources::ImageResourcePool>& pool) AppGLFW(std::unique_ptr<utils::log::ILog>& log, std::unique_ptr<pixelarium::resources::ImageResourcePool>& pool)
: AppGLFW(log) : AppGLFW(log)
@@ -57,13 +54,15 @@ class AppGLFW
private: private:
// LogLevelSelection log_level_ = static_cast<LogLevelSelection>(0); // LogLevelSelection log_level_ = static_cast<LogLevelSelection>(0);
utils::log::ILog* logger_; utils::log::ILog& logger_;
resources::ImageResourcePool* pool_; resources::ImageResourcePool* pool_;
GLFWwindow* window = nullptr; GLFWwindow* window = nullptr;
ImGuiWindowFlags window_flags_ = 0; ImGuiWindowFlags window_flags_ = 0;
std::shared_ptr<pixelarium::imaging::PixelariumImage> img_; std::shared_ptr<pixelarium::imaging::PixelariumImage> img_;
pixelarium::render::CvMatRender render_; pixelarium::render::CvMatRender render_;
bool imagep_{false}; bool imagep_{false};
bool demop_{false};
int log_level_{0};
ImVec2 curr_dim_; ImVec2 curr_dim_;
}; };
+8 -2
View File
@@ -1,8 +1,14 @@
#pragma once #pragma once
/*-- Gets filled in during the cmake configuration step --*/ /*-- Gets filled in during the cmake configuration step --*/
#cmakedefine PIXELARIUM_TITLE "@PIXELARIUM_TITLE@" #cmakedefine PIXELARIUM_TITLE "@PIXELARIUM_TITLE@"
#define MAINMENUNAME "Menu" #define MAINMENUNAME "Menu"
#define FILEMENUNAME "File" #define FILEMENUNAME "File"
#define LOGLEVELSELECT "Log Level"
#define SHOWIMGUIDEMOS "ImGui Demos"
namespace
{
const char* LOGLEVELS[] = {"Trace", "Debug", "Info", "Warning", "Error"};
}