Unified logging: Replace LogSystem with EditorConsoleSink
- Created EditorConsoleSink (implements ILogSink interface) - EditorConsoleSink stores logs in memory buffer (max 1000 entries) - Added to Debug::Logger in Application::Initialize() - ConsolePanel now reads from EditorConsoleSink via static GetInstance() - Removed separate LogSystem singleton - Removed editor/src/Core/LogEntry.h (no longer needed) Now Editor and Engine share the same Debug::Logger, with ConsolePanel displaying logs via EditorConsoleSink.
This commit is contained in:
@@ -1,24 +1,19 @@
|
||||
#include "ConsolePanel.h"
|
||||
#include "Managers/LogSystem.h"
|
||||
#include "Core/LogEntry.h"
|
||||
#include "Core/EditorConsoleSink.h"
|
||||
#include <XCEngine/Debug/Logger.h>
|
||||
#include <imgui.h>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
|
||||
ConsolePanel::ConsolePanel() : Panel("Console") {
|
||||
LogSystem::Get().AddLog(::XCEngine::Debug::LogLevel::Info, "Engine initialized successfully");
|
||||
LogSystem::Get().AddLog(::XCEngine::Debug::LogLevel::Info, "Loading default scene...");
|
||||
LogSystem::Get().AddLog(::XCEngine::Debug::LogLevel::Warning, "Missing material on object 'Cube'");
|
||||
LogSystem::Get().AddLog(::XCEngine::Debug::LogLevel::Error, "Failed to load texture: 'Assets/Textures/missing.png'");
|
||||
LogSystem::Get().AddLog(::XCEngine::Debug::LogLevel::Info, "Scene loaded successfully");
|
||||
}
|
||||
|
||||
void ConsolePanel::Render() {
|
||||
ImGui::Begin(m_name.c_str(), nullptr, ImGuiWindowFlags_None);
|
||||
|
||||
if (ImGui::Button("Clear")) {
|
||||
LogSystem::Get().Clear();
|
||||
Debug::EditorConsoleSink::GetInstance()->Clear();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
|
||||
@@ -57,17 +52,21 @@ void ConsolePanel::Render() {
|
||||
|
||||
ImGui::BeginChild("LogScroll", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
|
||||
|
||||
const auto& logs = Debug::EditorConsoleSink::GetInstance()->GetLogs();
|
||||
size_t logIndex = 0;
|
||||
for (const auto& log : LogSystem::Get().GetLogs()) {
|
||||
for (const auto& log : logs) {
|
||||
bool shouldShow = false;
|
||||
switch (log.level) {
|
||||
case ::XCEngine::Debug::LogLevel::Info:
|
||||
case ::XCEngine::Debug::LogLevel::Verbose:
|
||||
case ::XCEngine::Debug::LogLevel::Debug:
|
||||
shouldShow = m_showInfo;
|
||||
break;
|
||||
case ::XCEngine::Debug::LogLevel::Warning:
|
||||
shouldShow = m_showWarning;
|
||||
break;
|
||||
case ::XCEngine::Debug::LogLevel::Error:
|
||||
case ::XCEngine::Debug::LogLevel::Fatal:
|
||||
shouldShow = m_showError;
|
||||
break;
|
||||
}
|
||||
@@ -80,6 +79,8 @@ void ConsolePanel::Render() {
|
||||
const char* prefix;
|
||||
|
||||
switch (log.level) {
|
||||
case ::XCEngine::Debug::LogLevel::Verbose:
|
||||
case ::XCEngine::Debug::LogLevel::Debug:
|
||||
case ::XCEngine::Debug::LogLevel::Info:
|
||||
color = ImVec4(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
prefix = "[INFO] ";
|
||||
@@ -89,6 +90,7 @@ void ConsolePanel::Render() {
|
||||
prefix = "[WARN] ";
|
||||
break;
|
||||
case ::XCEngine::Debug::LogLevel::Error:
|
||||
case ::XCEngine::Debug::LogLevel::Fatal:
|
||||
color = ImVec4(1.0f, 0.3f, 0.3f, 1.0f);
|
||||
prefix = "[ERROR]";
|
||||
break;
|
||||
@@ -96,11 +98,10 @@ void ConsolePanel::Render() {
|
||||
|
||||
ImGui::PushID(static_cast<int>(logIndex));
|
||||
|
||||
std::string timestampStr = "[" + log.timestamp + "] ";
|
||||
ImGui::TextColored(ImVec4(0.4f, 0.4f, 0.4f, 1.0f), "%s", timestampStr.c_str());
|
||||
ImGui::TextColored(ImVec4(0.4f, 0.4f, 0.4f, 1.0f), "%s", log.message.CStr());
|
||||
ImGui::SameLine();
|
||||
|
||||
std::string fullMessage = std::string(prefix) + log.message;
|
||||
std::string fullMessage = std::string(prefix) + log.message.CStr();
|
||||
ImGui::TextColored(color, "%s", fullMessage.c_str());
|
||||
|
||||
if (ImGui::IsItemClicked()) {
|
||||
@@ -111,11 +112,6 @@ void ConsolePanel::Render() {
|
||||
logIndex++;
|
||||
}
|
||||
|
||||
if (m_scrollToBottom && !LogSystem::Get().GetLogs().empty()) {
|
||||
ImGui::SetScrollHereY(1.0f);
|
||||
m_scrollToBottom = false;
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user