Minor update - Log system rework

+ GetLogLevelInfo return a struct of info relative to a type of log

+ filtered log in the UI
This commit is contained in:
2025-01-19 14:41:37 +01:00
parent a88ed06198
commit 161166837f
3 changed files with 135 additions and 118 deletions

View File

@@ -522,87 +522,72 @@ void imguiManager::WidgetEngineSettingsWindow(ApplicationClass* app)
void imguiManager::WidgetLogWindow(ApplicationClass* app)
{
static bool logLevelVisible[Logger::LogLevelCount] = { true };
ImGui::Begin("Log Window");
ImGui::Begin("Log", &showLogWindow);
// Filtre de recherche
static ImGuiTextFilter filter;
filter.Draw("Filter (inc,-exc)", 180);
// Champ de saisie pour le filtre
static char filterBuffer[256] = "";
ImGui::InputText("Filter", filterBuffer, IM_ARRAYSIZE(filterBuffer));
// Place the menu on the same line as the filter
ImGui::SameLine();
ImGui::SameLine();
// Menu d<>roulant pour les niveaux de log
if (ImGui::BeginMenu("Log Levels"))
{
for (size_t i = 0; i < Logger::LogLevelCount; ++i)
{
bool isVisible = !Logger::Get().m_disabledLogLevels[i];
if (ImGui::Checkbox(Logger::Get().GetLogLevelInfo(static_cast<Logger::LogLevel>(i)).name, &isVisible))
{
Logger::Get().m_disabledLogLevels[i] = !isVisible;
}
}
ImGui::EndMenu();
}
// Menu d<>roulant pour les niveaux de log
if (ImGui::BeginMenu("Log Levels"))
const auto& logBuffer = Logger::Get().GetLogBuffer();
std::vector<Logger::LogEntry> logfiltered;
int logCount = logBuffer.size();
int filteredLogCount = 0;
// Affichage des logs filtr<74>s
ImGui::BeginChild("Log");
// Compter le nombre de logs qui passent le filtre et les ajouter a la liste des message a afficher
for (const auto& log : logBuffer)
{
for (size_t i = 0; i < Logger::LogLevelCount; ++i)
if (filter.PassFilter(log.message.c_str()) && !Logger::Get().m_disabledLogLevels[static_cast<size_t>(log.level)])
{
bool isVisible = logLevelVisible[i];
if (ImGui::Checkbox(Logger::LogLevelToString(static_cast<Logger::LogLevel>(i)), &isVisible))
{
logLevelVisible[i] = isVisible;
if (isVisible)
{
Logger::Get().m_disabledLogLevels.erase(static_cast<Logger::LogLevel>(i));
}
else
{
Logger::Get().m_disabledLogLevels.insert(static_cast<Logger::LogLevel>(i));
}
}
}
ImGui::EndMenu();
}
// R<>cup<75>rer les logs depuis le logBuffer
const std::deque<Logger::LogEntry>& logs = logBuffer;
// Afficher les logs dans ImGui avec le filtre
ImGui::BeginChild("LogScrollRegion", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
ImGuiListClipper clipper;
clipper.Begin(logs.size());
while (clipper.Step())
{
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; ++i)
{
if (strstr(logs[i].message.c_str(), filterBuffer) != nullptr)
{
ImVec4 color;
switch (logs[i].level)
{
case Logger::LogLevel::Error:
color = ImVec4(1.0f, 0.0f, 0.0f, 1.0f); // Rouge pour les messages d'erreur
break;
case Logger::LogLevel::Warning:
color = ImVec4(1.0f, 1.0f, 0.0f, 1.0f); // Jaune pour les messages d'avertissement
break;
case Logger::LogLevel::Info:
color = ImVec4(0.0f, 1.0f, 0.0f, 1.0f); // Vert pour les messages d'info
break;
case Logger::LogLevel::Initialize:
case Logger::LogLevel::Shutdown:
default:
color = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // Blanc par d<>faut
break;
}
ImGui::PushStyleColor(ImGuiCol_Text, color);
ImGui::TextUnformatted(logs[i].message.c_str());
ImGui::PopStyleColor();
}
logfiltered.push_back(log);
filteredLogCount++;
}
}
clipper.End();
// Scroll to the bottom of the log window
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
if (filteredLogCount == 0)
{
ImGui::SetScrollHereY(1.0f);
ImGui::Text("No logs to display.");
}
else
{
ImGuiListClipper clipper;
clipper.Begin(logCount);
while (clipper.Step())
{
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
{
if (i < logfiltered.size()) {
const auto& log = logfiltered[i];
ImGui::TextColored(Logger::Get().GetLogLevelInfo(log.level).color, log.message.c_str());
}
}
}
clipper.End();
}
ImGui::EndChild();
ImGui::EndChild();
ImGui::End();
ImGui::End();
}