galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
LogPanel.cpp
Go to the documentation of this file.
1
7
10
11#include "LogPanel.hpp"
12
13namespace galaxy
14{
16 {
17 m_logs.clear();
18 }
19
20 void EditorSink::sink(const LogMessage& message)
21 {
22 m_logs.emplace_back(message);
23 }
24
26 {
27 m_logs.clear();
28 }
29
30 const std::vector<LogMessage>& EditorSink::get_messages() const
31 {
32 return m_logs;
33 }
34
36 : m_icon_size {32, 32}
37 , m_show_info {true}
38 , m_show_warning {true}
39 , m_show_error {true}
40 {
42 m_show = true;
43 }
44
46 {
47 }
48
50 {
51 if (ImGui::Begin(ICON_MDI_POST " Log", nullptr, ImGuiWindowFlags_AlwaysVerticalScrollbar))
52 {
53 if (ImGui::Button("Clear"))
54 {
55 m_sink.clear();
56 }
57
58 ImGui::SameLine();
59 ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - 56);
60
61 if (ImGui::Button(ICON_MDI_INFORMATION, m_icon_size))
62 {
64 }
65
66 ImGui::SameLine();
67
68 if (ImGui::Button(ICON_MDI_ALERT, m_icon_size))
69 {
71 }
72
73 ImGui::SameLine();
74
75 if (ImGui::Button(ICON_MDI_ALERT_CIRCLE, m_icon_size))
76 {
78 }
79
80 constexpr const auto flags = ImGuiTableFlags_BordersV | ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_ScrollY | ImGuiTableFlags_ContextMenuInBody;
81
82 if (ImGui::BeginTable("LogTable", 5, flags))
83 {
84 ImGui::TableSetupColumn("Level");
85 ImGui::TableSetupColumn("Time");
86 ImGui::TableSetupColumn("File");
87 ImGui::TableSetupColumn("Line");
88 ImGui::TableSetupColumn("Message");
89 ImGui::TableHeadersRow();
90
91 for (const auto& msg : m_sink.get_messages())
92 {
93 if (msg.level == LogLevel::INFO && !m_show_info)
94 {
95 continue;
96 }
97 else if (msg.level == LogLevel::WARNING && !m_show_warning)
98 {
99 continue;
100 }
101 else if ((msg.level == LogLevel::ERROR || msg.level == LogLevel::FATAL) && !m_show_error)
102 {
103 continue;
104 }
105
106 ImGui::TableNextRow();
107
108 ImGui::TableSetColumnIndex(0);
109 std::string level {magic_enum::enum_name<LogLevel>(msg.level)};
110 ImGui::TextWrapped(level.c_str());
111
112 ImGui::TableSetColumnIndex(1);
113 ImGui::TextWrapped(msg.time.c_str());
114
115 ImGui::TableSetColumnIndex(2);
116 ImGui::TextWrapped(msg.file.c_str());
117
118 ImGui::TableSetColumnIndex(3);
119 ImGui::TextWrapped(std::format("{0}", msg.line).c_str());
120
121 ImGui::TableSetColumnIndex(4);
122 ImGui::TextWrapped(msg.message.c_str());
123 }
124
125 ImGui::EndTable();
126 }
127 }
128
129 ImGui::End();
130 }
131} // namespace galaxy
#define GALAXY_ADD_SINK(sink,...)
Definition Log.hpp:28
Sink to display log messages in overlay editor.
Definition LogPanel.hpp:21
std::vector< LogMessage > m_logs
Stored logs.
Definition LogPanel.hpp:56
void sink(const LogMessage &message) override
Sink the message.
Definition LogPanel.cpp:20
void clear()
Clear all logs stored.
Definition LogPanel.cpp:25
virtual ~EditorSink() noexcept
Destructor.
Definition LogPanel.cpp:15
const std::vector< LogMessage > & get_messages() const
Get all stored logs.
Definition LogPanel.cpp:30
EditorSink m_sink
Bridges the panel and the log system.
Definition LogPanel.hpp:84
bool m_show_info
Level filter for info.
Definition LogPanel.hpp:94
ImVec2 m_icon_size
Icon size for buttons.
Definition LogPanel.hpp:89
LogPanel() noexcept
Constructor.
Definition LogPanel.cpp:35
void draw() override
Draw config panel.
Definition LogPanel.cpp:49
bool m_show_error
Level filter for error.
Definition LogPanel.hpp:104
virtual ~LogPanel() noexcept
Destructor.
Definition LogPanel.cpp:45
bool m_show_warning
Level filter for warning.
Definition LogPanel.hpp:99
#define ICON_MDI_POST
#define ICON_MDI_ALERT
#define ICON_MDI_ALERT_CIRCLE
#define ICON_MDI_INFORMATION
Application.hpp galaxy.
@ WARNING
Warning Log Level.
Definition LogLevel.hpp:33
@ FATAL
Fatal Log Level.
Definition LogLevel.hpp:43
@ INFO
Info Log Level.
Definition LogLevel.hpp:28
@ ERROR
Error Log Level.
Definition LogLevel.hpp:38
Parts of a log message to be passed to sinks.