2023-07-23 23:37:47 +02:00
|
|
|
#include "content/views/view_logs.hpp"
|
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2023-07-23 23:37:47 +02:00
|
|
|
#include <hex/helpers/logger.hpp>
|
|
|
|
|
2024-01-28 22:14:59 +01:00
|
|
|
#include <fonts/codicons_font.h>
|
|
|
|
|
2023-07-23 23:37:47 +02:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
2023-11-21 13:47:50 +01:00
|
|
|
ViewLogs::ViewLogs() : View::Floating("hex.builtin.view.logs.name") {
|
2024-01-08 21:51:48 +01:00
|
|
|
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.view.logs.name" }, ICON_VS_BRACKET_ERROR, 2500, Shortcut::None, [&, this] {
|
2023-07-23 23:37:47 +02:00
|
|
|
this->getWindowOpenState() = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static ImColor getColor(std::string_view level) {
|
|
|
|
if (level.contains("DEBUG"))
|
2023-11-16 22:24:06 +01:00
|
|
|
return ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerDebug);
|
2023-07-23 23:37:47 +02:00
|
|
|
else if (level.contains("INFO"))
|
2023-11-16 22:24:06 +01:00
|
|
|
return ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerInfo);
|
2023-07-23 23:37:47 +02:00
|
|
|
else if (level.contains("WARN"))
|
2023-11-16 22:24:06 +01:00
|
|
|
return ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerWarning);
|
2023-07-23 23:37:47 +02:00
|
|
|
else if (level.contains("ERROR"))
|
2023-11-16 22:24:06 +01:00
|
|
|
return ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerError);
|
2023-07-23 23:37:47 +02:00
|
|
|
else if (level.contains("FATAL"))
|
2023-11-16 22:24:06 +01:00
|
|
|
return ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerFatal);
|
2023-07-23 23:37:47 +02:00
|
|
|
return ImGui::GetStyleColorVec4(ImGuiCol_Text);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool shouldDisplay(std::string_view messageLevel, int currLevel) {
|
2023-12-28 20:34:49 +01:00
|
|
|
if (messageLevel.contains("[DEBUG]"))
|
|
|
|
return currLevel <= 0;
|
|
|
|
else if (messageLevel.contains("[INFO]"))
|
|
|
|
return currLevel <= 1;
|
|
|
|
else if (messageLevel.contains("[WARN]"))
|
|
|
|
return currLevel <= 2;
|
|
|
|
else if (messageLevel.contains("[ERROR]"))
|
|
|
|
return currLevel <= 3;
|
|
|
|
else if (messageLevel.contains("[FATAL]"))
|
|
|
|
return currLevel <= 4;
|
|
|
|
else
|
|
|
|
return false;
|
2023-07-23 23:37:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewLogs::drawContent() {
|
2023-12-19 13:10:25 +01:00
|
|
|
ImGui::Combo("hex.builtin.view.logs.log_level"_lang, &m_logLevel, "DEBUG\0INFO\0WARNING\0ERROR\0FATAL\0");
|
2023-07-23 23:37:47 +02:00
|
|
|
|
2023-11-21 13:47:50 +01:00
|
|
|
if (ImGui::BeginTable("##logs", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_ScrollY)) {
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.view.logs.component"_lang, ImGuiTableColumnFlags_WidthFixed, 100_scaled);
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.view.logs.message"_lang);
|
|
|
|
ImGui::TableSetupScrollFreeze(0, 1);
|
2023-07-23 23:37:47 +02:00
|
|
|
|
2023-11-21 13:47:50 +01:00
|
|
|
ImGui::TableHeadersRow();
|
2023-07-23 23:37:47 +02:00
|
|
|
|
2023-11-21 13:47:50 +01:00
|
|
|
const auto &logs = log::impl::getLogEntries();
|
2023-12-28 20:34:49 +01:00
|
|
|
for (const auto &log : logs | std::views::reverse) {
|
|
|
|
if (!shouldDisplay(log.level, m_logLevel)) {
|
|
|
|
continue;
|
2023-11-21 13:47:50 +01:00
|
|
|
}
|
2023-12-28 20:34:49 +01:00
|
|
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextUnformatted(log.project.c_str());
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, getColor(log.level).Value);
|
|
|
|
ImGui::TextUnformatted(log.message.c_str());
|
|
|
|
ImGui::PopStyleColor();
|
2023-07-23 23:37:47 +02:00
|
|
|
}
|
|
|
|
|
2023-11-21 13:47:50 +01:00
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
2023-07-23 23:37:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|