2023-08-20 15:38:04 -04:00
|
|
|
#include "imgui/imgui.h"
|
|
|
|
|
#include "logger_sink.h"
|
|
|
|
|
|
|
|
|
|
namespace widgets
|
|
|
|
|
{
|
|
|
|
|
void LoggerSinkWidget::receive(slog::LogMsg log)
|
|
|
|
|
{
|
|
|
|
|
if (log.lvl >= sink_lvl)
|
|
|
|
|
{
|
|
|
|
|
mtx.lock();
|
2023-08-21 23:00:31 -04:00
|
|
|
new_item = true;
|
2023-08-20 15:38:04 -04:00
|
|
|
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());
|
2023-08-21 23:00:31 -04:00
|
|
|
}
|
|
|
|
|
if (new_item)
|
|
|
|
|
{
|
2023-09-29 14:03:21 -04:00
|
|
|
ImGui::SetScrollHereY(1.0f);
|
2023-08-21 23:00:31 -04:00
|
|
|
new_item = false;
|
2023-08-20 15:38:04 -04:00
|
|
|
}
|
2023-09-03 10:16:28 -04:00
|
|
|
if(ImGui::IsWindowAppearing())
|
|
|
|
|
new_item = true;
|
2023-08-20 15:38:04 -04:00
|
|
|
mtx.unlock();
|
|
|
|
|
}
|
|
|
|
|
}
|