Unravel Engine C++ Reference
Loading...
Searching...
No Matches
console_log_panel.h
Go to the documentation of this file.
1#pragma once
2#include "../panel_base.h"
4
5#include <hpp/optional.hpp>
6#include <hpp/ring_buffer.hpp>
7#include <hpp/small_vector.hpp>
8
9// #include <console/console.h>
10#include <logging/logging.h>
11
12#include <array>
13#include <atomic>
14#include <string>
15#include <vector>
16
17namespace unravel
18{
19
20class console_log_panel : public panel_base, public sinks::base_sink<std::mutex>
21{
22public:
23 using mem_buf = hpp::small_vector<char, 250>;
24
26 {
27 std::string filename{};
28 std::string funcname{};
29 int line{0};
30 };
31
32 struct log_entry
33 {
35
36 level::level_enum level{level::off};
38
39 uint64_t id{};
40 };
41
43 {
44 uint64_t id{};
45 level::level_enum level{level::off};
46 std::string text;
47 std::string filename;
48 std::string funcname;
49 int line{0};
50 };
51
52 using display_entries_t = hpp::small_vector<log_entry, 1024>;
53 using entries_t = hpp::stack_ringbuffer<log_entry, 1024>;
54
55 explicit console_log_panel(const char* name);
56 void sink_it_(const details::log_msg& msg) override;
57 void flush_() override;
58
59 void draw_ui(rtti::context& ctx) override;
60 auto get_window_flags() const -> ImGuiWindowFlags override;
61 void draw();
62
63 void draw_details();
64 auto draw_last_log() -> bool;
65
67
68 void on_play();
69 void on_recompile();
70
75 auto snapshot_logs(level::level_enum min_level, size_t max_count, uint64_t after_id = 0) const
76 -> std::vector<log_snapshot_entry>;
77
78private:
79 void select_log(const log_entry& entry);
80 void clear_log();
81 void open_log(const log_entry& entry);
82 auto has_new_entries() const -> bool;
83 void set_has_new_entries(bool val);
84
85 auto draw_log(const log_entry& msg, int num_lines) -> bool;
86 void draw_range(const hpp::string_view& formatted, size_t start, size_t end);
87 void draw_filter_button(level::level_enum level);
88
89 std::array<bool, size_t(level::n_levels)> enabled_categories_{};
90
91 mutable std::recursive_mutex entries_mutex_;
93 entries_t entries_;
95 std::atomic<bool> has_new_entries_ = {false};
96
97 std::atomic<int64_t> new_entries_begin_idx_{-1};
98
99 ImGuiTextFilter filter_;
100
101 uint64_t current_id_{};
102 hpp::optional<log_entry> selected_log_{};
103
104 bool clear_on_play_{true};
105 bool clear_on_recompile_{true};
106};
107} // namespace unravel
console_log_panel(const char *name)
auto snapshot_logs(level::level_enum min_level, size_t max_count, uint64_t after_id=0) const -> std::vector< log_snapshot_entry >
Snapshot recent log entries (thread-safe). Newest-last order. Filters by min_level (inclusive) and op...
hpp::stack_ringbuffer< log_entry, 1024 > entries_t
hpp::small_vector< log_entry, 1024 > display_entries_t
hpp::small_vector< char, 250 > mem_buf
void draw_ui(rtti::context &ctx) override
auto get_window_flags() const -> ImGuiWindowFlags override
void sink_it_(const details::log_msg &msg) override
std::string name
Definition hub.cpp:33
Hash specialization for batch_key to enable use in std::unordered_map.
std::vector< math::vec3 > start
log_source source
mem_buf formatted
level::level_enum level
std::string funcname
std::string filename
int line
level::level_enum level
std::string text