mirror of
https://github.com/SatDump/SatDump
synced 2026-08-13 17:47:30 -04:00
50 lines
No EOL
1.6 KiB
C++
50 lines
No EOL
1.6 KiB
C++
#include "imgui/imgui.h"
|
|
#include "logger_sink.h"
|
|
|
|
namespace widgets
|
|
{
|
|
void LoggerSinkWidget::receive(slog::LogMsg log)
|
|
{
|
|
if (log.lvl >= sink_lvl)
|
|
{
|
|
mtx.lock();
|
|
new_item = true;
|
|
all_lines.push_back({ log.lvl, format_log(log, false) });
|
|
if (all_lines.size() == max_lines)
|
|
all_lines.pop_front();
|
|
mtx.unlock();
|
|
}
|
|
}
|
|
|
|
void LoggerSinkWidget::draw()
|
|
{
|
|
mtx.lock();
|
|
for (LogLine& ll : all_lines)
|
|
{
|
|
std::string timestamp = ll.str.substr(0, 24);
|
|
std::string text = ll.str.substr(24, ll.str.size());
|
|
|
|
ImGui::Text("%s", timestamp.c_str());
|
|
ImGui::SameLine();
|
|
|
|
if (ll.lvl == slog::LOG_TRACE)
|
|
ImGui::TextColored(ImColor(255, 255, 255), "%s", text.c_str());
|
|
else if (ll.lvl == slog::LOG_DEBUG)
|
|
ImGui::TextColored(ImColor(0, 255, 255), "%s", text.c_str());
|
|
else if (ll.lvl == slog::LOG_INFO)
|
|
ImGui::TextColored(ImColor(0, 255, 0), "%s", text.c_str());
|
|
else if (ll.lvl == slog::LOG_WARN)
|
|
ImGui::TextColored(ImColor(255, 255, 0), "%s", text.c_str());
|
|
else if (ll.lvl == slog::LOG_ERROR)
|
|
ImGui::TextColored(ImColor(255, 0, 0), "%s", text.c_str());
|
|
else if (ll.lvl == slog::LOG_CRIT)
|
|
ImGui::TextColored(ImColor(255, 0, 255), "%s", text.c_str());
|
|
}
|
|
if (new_item)
|
|
{
|
|
ImGui::SetScrollY(ImGui::GetScrollMaxY());
|
|
new_item = false;
|
|
}
|
|
mtx.unlock();
|
|
}
|
|
} |