43 lines
945 B
C++
43 lines
945 B
C++
|
|
#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
|