logger business
This commit is contained in:
committed by
Kueffner, Maximilian
parent
566dd112ff
commit
25b0ef0ff5
@@ -4,6 +4,7 @@
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <spdlog/sinks/basic_file_sink.h>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "ILog.hpp"
|
||||
|
||||
@@ -34,29 +35,37 @@ void SpdLogger::Error(const std::string& msg) { this->logger_->error(msg); }
|
||||
|
||||
void SpdLogger::ChangeLevel(LogLevel lvl)
|
||||
{
|
||||
std::stringstream st{};
|
||||
st << std::format("with argument {}", static_cast<int>(lvl));
|
||||
switch (lvl)
|
||||
{
|
||||
case LogLevel::Trace:
|
||||
this->logger_->set_level(spdlog::level::trace);
|
||||
spdlog::flush_on(spdlog::level::trace);
|
||||
st << "Trace";
|
||||
break;
|
||||
case LogLevel::Info:
|
||||
this->logger_->set_level(spdlog::level::info);
|
||||
spdlog::flush_on(spdlog::level::info);
|
||||
st << "Info";
|
||||
break;
|
||||
case LogLevel::Warn:
|
||||
this->logger_->set_level(spdlog::level::warn);
|
||||
spdlog::flush_on(spdlog::level::warn);
|
||||
st << "Warn";
|
||||
break;
|
||||
case LogLevel::Error:
|
||||
this->logger_->set_level(spdlog::level::err);
|
||||
spdlog::flush_on(spdlog::level::err);
|
||||
st << "Error";
|
||||
break;
|
||||
case LogLevel::Debug:
|
||||
default:
|
||||
this->logger_->set_level(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
@@ -10,6 +10,7 @@
|
||||
#include "portable-file-dialogs.h"
|
||||
#include "rendering/CvMatRender.hpp"
|
||||
#include "uiresources.h"
|
||||
#include "utilities/ILog.hpp"
|
||||
|
||||
using namespace pixelarium::imaging;
|
||||
|
||||
@@ -134,7 +135,8 @@ int pixelarium::ui::AppGLFW::Run()
|
||||
ImGui::DockSpaceOverViewport(ImGui::GetID("Backspace"));
|
||||
|
||||
this->MenuBar();
|
||||
|
||||
if (demop_)
|
||||
ImGui::ShowDemoWindow(&this->demop_);
|
||||
if (this->imagep_)
|
||||
{
|
||||
// auto render = render::CvMatRender(this->_img);
|
||||
@@ -200,6 +202,24 @@ void pixelarium::ui::AppGLFW::MenuBar()
|
||||
// main menu
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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()};
|
||||
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->render_ = pixelarium::render::CvMatRender(this->img_);
|
||||
|
||||
+10
-11
@@ -29,19 +29,16 @@ enum LogLevelSelection
|
||||
class AppGLFW
|
||||
{
|
||||
public:
|
||||
AppGLFW() { this->InitMainWindow(); }
|
||||
AppGLFW(std::unique_ptr<utils::log::ILog>& log) : AppGLFW()
|
||||
explicit AppGLFW(std::unique_ptr<utils::log::ILog>& log) : logger_(*log)
|
||||
{
|
||||
logger_ = log.get();
|
||||
if (logger_)
|
||||
{
|
||||
logger_->Debug(std::format("{}: Initiating a new window", __FUNCTION__).c_str());
|
||||
logger_.Debug(std::format("{}: Initiating a new window", __FUNCTION__).c_str());
|
||||
|
||||
if (pool_)
|
||||
{
|
||||
logger_->Debug(std::format("{}: We have an image resource pool!", __FUNCTION__).c_str());
|
||||
}
|
||||
if (pool_)
|
||||
{
|
||||
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(log)
|
||||
@@ -57,13 +54,15 @@ class AppGLFW
|
||||
|
||||
private:
|
||||
// LogLevelSelection log_level_ = static_cast<LogLevelSelection>(0);
|
||||
utils::log::ILog* logger_;
|
||||
utils::log::ILog& logger_;
|
||||
resources::ImageResourcePool* pool_;
|
||||
GLFWwindow* window = nullptr;
|
||||
ImGuiWindowFlags window_flags_ = 0;
|
||||
std::shared_ptr<pixelarium::imaging::PixelariumImage> img_;
|
||||
pixelarium::render::CvMatRender render_;
|
||||
bool imagep_{false};
|
||||
bool demop_{false};
|
||||
int log_level_{0};
|
||||
ImVec2 curr_dim_;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
/*-- Gets filled in during the cmake configuration step --*/
|
||||
#cmakedefine PIXELARIUM_TITLE "@PIXELARIUM_TITLE@"
|
||||
|
||||
#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"};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user