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:
43
editor/src/Core/EditorConsoleSink.cpp
Normal file
43
editor/src/Core/EditorConsoleSink.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "Core/EditorConsoleSink.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Debug {
|
||||
|
||||
EditorConsoleSink* EditorConsoleSink::GetInstance() {
|
||||
static EditorConsoleSink instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
EditorConsoleSink::EditorConsoleSink() = default;
|
||||
|
||||
EditorConsoleSink::~EditorConsoleSink() = default;
|
||||
|
||||
void EditorConsoleSink::Log(const LogEntry& entry) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (m_logs.size() >= MAX_LOGS) {
|
||||
m_logs.erase(m_logs.begin());
|
||||
}
|
||||
m_logs.push_back(entry);
|
||||
if (m_callback) {
|
||||
m_callback();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorConsoleSink::Flush() {
|
||||
}
|
||||
|
||||
const std::vector<LogEntry>& EditorConsoleSink::GetLogs() const {
|
||||
return m_logs;
|
||||
}
|
||||
|
||||
void EditorConsoleSink::Clear() {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_logs.clear();
|
||||
}
|
||||
|
||||
void EditorConsoleSink::SetCallback(std::function<void()> callback) {
|
||||
m_callback = std::move(callback);
|
||||
}
|
||||
|
||||
} // namespace Debug
|
||||
} // namespace XCEngine
|
||||
34
editor/src/Core/EditorConsoleSink.h
Normal file
34
editor/src/Core/EditorConsoleSink.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/Debug/ILogSink.h>
|
||||
#include <XCEngine/Debug/LogEntry.h>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Debug {
|
||||
|
||||
class EditorConsoleSink : public ILogSink {
|
||||
public:
|
||||
static EditorConsoleSink* GetInstance();
|
||||
|
||||
EditorConsoleSink();
|
||||
~EditorConsoleSink() override;
|
||||
|
||||
void Log(const LogEntry& entry) override;
|
||||
void Flush() override;
|
||||
|
||||
const std::vector<LogEntry>& GetLogs() const;
|
||||
void Clear();
|
||||
void SetCallback(std::function<void()> callback);
|
||||
|
||||
private:
|
||||
mutable std::mutex m_mutex;
|
||||
std::vector<LogEntry> m_logs;
|
||||
std::function<void()> m_callback;
|
||||
static constexpr size_t MAX_LOGS = 1000;
|
||||
};
|
||||
|
||||
} // namespace Debug
|
||||
} // namespace XCEngine
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <XCEngine/Debug/LogLevel.h>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
|
||||
struct LogEntry {
|
||||
::XCEngine::Debug::LogLevel level;
|
||||
std::string message;
|
||||
std::string timestamp;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user