LogWidget Class
Debug widget for displaying log output in a scrollable ImGui panel. More...
Declaration
Base class
| class | ImGuiWidget |
|
Abstract base class for ImGui widgets rendered in debug overlays. More... | |
Public Constructors Index
| LogWidget ()=default | |
Public Destructor Index
| ~LogWidget () override=default | |
Public Member Functions Index
| void | addLog (LogLevel level, const std::string &scope, const std::string &message) |
|
Adds a log entry to the appropriate scope buffer(s). More... | |
| void | debug (const std::string &scope, const std::string &message) |
|
Convenience method to add a debug-level log entry. More... | |
| void | info (const std::string &scope, const std::string &message) |
|
Convenience method to add an info-level log entry. More... | |
| void | warn (const std::string &scope, const std::string &message) |
|
Convenience method to add a warning-level log entry. More... | |
| void | error (const std::string &scope, const std::string &message) |
|
Convenience method to add an error-level log entry. More... | |
| void | clear () noexcept |
|
Clears all log entries from all buffers. More... | |
| void | setMaxEntries (std::size_t max) noexcept |
|
Sets the maximum number of entries to retain per scope. More... | |
| void | setAutoScroll (bool enabled) noexcept |
|
Enables or disables auto-scrolling to the latest entry. More... | |
| void | setFilterLevel (LogLevel level) noexcept |
|
Sets the minimum log level to display. More... | |
| void | setScopeFilterCallback (std::function< void(const std::string &)> callback) |
|
Sets a callback to be invoked when the scope filter changes. More... | |
| std::size_t | entryCount () const noexcept |
|
Returns the current number of log entries in the active buffer. More... | |
| void | draw () override |
|
Renders the log widget using ImGui. More... | |
Private Member Functions Index
| void | collectScope (const std::string &scope) |
|
Adds a scope to the collection if not already present. More... | |
| void | addToBuffer (std::vector< LogEntry > &buffer, LogEntry entry) |
|
Adds an entry to a specific buffer, trimming if necessary. More... | |
| const std::vector< LogEntry > & | activeBuffer () const |
|
Returns the currently active buffer based on scope selection. More... | |
Private Member Attributes Index
| std::unordered_map< std::string, std::vector< LogEntry > > | scopeBuffers_ |
|
Per-scope log buffers. Key is scope name, value is entry vector. More... | |
| std::size_t | maxEntries_ = 1000 |
|
Maximum number of entries to retain per scope buffer. More... | |
| std::mutex | bufferMutex_ |
|
Mutex for thread-safe access to the log buffers. More... | |
| bool | autoScroll_ = true |
|
Whether to automatically scroll to the bottom on new entries. More... | |
| bool | prevAutoScroll_ = true |
|
Previous autoScroll state to detect toggle events. More... | |
| bool | scrollUpOneEntry_ = false |
|
Flag to nudge scroll up one entry when auto-scroll is disabled. More... | |
| bool | scrollToBottom_ = false |
|
Flag to indicate that new content was added and scroll is needed. More... | |
| bool | wasAtBottom_ = true |
|
Tracks if user was at bottom in the previous frame. More... | |
| std::atomic< bool > | acceptNewEntries_ {true} |
|
Whether new entries are currently accepted into the buffer. More... | |
| std::atomic< std::size_t > | skippedEntries_ {0} |
|
Counts how many log entries were skipped while logging was paused. More... | |
| LogLevel | filterLevel_ = LogLevel::Debug |
|
Minimum log level to display (filters out lower levels). More... | |
| ImGuiTextFilter | textFilter_ |
|
Text filter for searching within log messages. More... | |
| int | filterLevelIndex_ = 0 |
|
Current filter level selection index for the combo box. More... | |
| std::vector< std::string > | collectedScopes_ |
|
Collection of all unique scopes seen in log entries. More... | |
| int | selectedScopeIndex_ = -1 |
|
Currently selected scope index in the combo box (0 = "All", -1 = "None"). More... | |
| std::string | activeScopeFilter_ |
|
Currently active scope filter (empty = show all). More... | |
| bool | loggingDisabled_ = true |
|
Whether logging is completely disabled (None selected). More... | |
| std::function< void(const std::string &)> | onScopeFilterChanged_ |
|
Callback function to notify external systems of scope filter changes. More... | |
Private Static Functions Index
| static ImVec4 | colorForLevel (LogLevel level) noexcept |
|
Returns an ImVec4 color for the given log level. More... | |
| static const char * | labelForLevel (LogLevel level) noexcept |
|
Returns a string label for the given log level. More... | |
| static std::string | currentTimestamp () noexcept |
|
Generates a simple timestamp string (HH:MM:SS.mmm). More... | |
Private Static Attributes Index
| static constexpr const char * | ALL_SCOPES_KEY = "__all__" |
|
Key for the "all scopes" combined view. More... | |
| static constexpr const char * | NONE_SCOPES_KEY = "__none__" |
|
Key for the "none" option that disables logging. More... | |
Description
Debug widget for displaying log output in a scrollable ImGui panel.
This widget maintains separate buffers for each log scope and renders them in a scrollable text area. It supports filtering by log level, clearing the buffer, and auto-scrolling to the latest messages.
Each scope has its own buffer with a maximum of 1000 entries, allowing efficient scope-based filtering without losing messages from other scopes.
This widget uses internal locking for adding log entries from multiple threads.
Definition at line 73 of file LogWidget.ixx.
Public Constructors
LogWidget()
| default |
Definition at line 282 of file LogWidget.ixx.
Public Destructor
~LogWidget()
| default |
Definition at line 283 of file LogWidget.ixx.
Public Member Functions
addLog()
| inline |
Adds a log entry to the appropriate scope buffer(s).
Thread-safe. Adds to both the scope-specific buffer and the "all" buffer.
Definition at line 290 of file LogWidget.ixx.
References helios::ext::imgui::widgets::LogEntry::level, helios::ext::imgui::widgets::LogEntry::message, helios::ext::imgui::widgets::LogEntry::scope and helios::ext::imgui::widgets::LogEntry::timestamp.
clear()
| inline noexcept |
Clears all log entries from all buffers.
Definition at line 367 of file LogWidget.ixx.
Referenced by draw.
debug()
| inline |
Convenience method to add a debug-level log entry.
- Parameters
-
scope The source scope or module name.
message The log message text.
Definition at line 330 of file LogWidget.ixx.
References addLog and helios::ext::imgui::widgets::Debug.
draw()
| inline virtual |
Renders the log widget using ImGui.
Definition at line 435 of file LogWidget.ixx.
References clear, helios::ext::imgui::widgets::LogEntry::level, helios::ext::imgui::widgets::LogEntry::message, helios::ext::imgui::widgets::LogEntry::scope and helios::ext::imgui::widgets::LogEntry::timestamp.
entryCount()
| inline nodiscard noexcept |
Returns the current number of log entries in the active buffer.
- Returns
The number of entries currently stored.
Definition at line 427 of file LogWidget.ixx.
error()
| inline |
Convenience method to add an error-level log entry.
- Parameters
-
scope The source scope or module name.
message The log message text.
Definition at line 360 of file LogWidget.ixx.
References addLog and helios::ext::imgui::widgets::Error.
info()
| inline |
Convenience method to add an info-level log entry.
- Parameters
-
scope The source scope or module name.
message The log message text.
Definition at line 340 of file LogWidget.ixx.
References addLog and helios::ext::imgui::widgets::Info.
setAutoScroll()
| inline noexcept |
Enables or disables auto-scrolling to the latest entry.
- Parameters
-
enabled True to enable auto-scroll.
Definition at line 396 of file LogWidget.ixx.
setFilterLevel()
| inline noexcept |
Sets the minimum log level to display.
- Parameters
-
level Entries below this level are hidden.
Definition at line 405 of file LogWidget.ixx.
setMaxEntries()
| inline noexcept |
Sets the maximum number of entries to retain per scope.
- Parameters
-
max The maximum buffer size.
Definition at line 378 of file LogWidget.ixx.
setScopeFilterCallback()
| inline |
Sets a callback to be invoked when the scope filter changes.
The callback receives the selected scope string, or an empty string when "All" is selected. Use this to integrate with LogManager::setScopeFilter().
- Parameters
-
callback Function to call on scope filter change.
Definition at line 418 of file LogWidget.ixx.
warn()
| inline |
Convenience method to add a warning-level log entry.
- Parameters
-
scope The source scope or module name.
message The log message text.
Definition at line 350 of file LogWidget.ixx.
References addLog and helios::ext::imgui::widgets::Warn.
Private Member Functions
activeBuffer()
| inline nodiscard |
Returns the currently active buffer based on scope selection.
Definition at line 208 of file LogWidget.ixx.
addToBuffer()
| inline |
Adds an entry to a specific buffer, trimming if necessary.
Definition at line 196 of file LogWidget.ixx.
collectScope()
| inline |
Adds a scope to the collection if not already present.
- Parameters
-
scope The scope to add.
Definition at line 186 of file LogWidget.ixx.
Private Member Attributes
acceptNewEntries_
|
Whether new entries are currently accepted into the buffer.
Definition at line 131 of file LogWidget.ixx.
activeScopeFilter_
|
Currently active scope filter (empty = show all).
Definition at line 166 of file LogWidget.ixx.
autoScroll_
|
Whether to automatically scroll to the bottom on new entries.
Definition at line 106 of file LogWidget.ixx.
bufferMutex_
| mutable |
Mutex for thread-safe access to the log buffers.
Definition at line 101 of file LogWidget.ixx.
collectedScopes_
|
Collection of all unique scopes seen in log entries.
Definition at line 156 of file LogWidget.ixx.
filterLevel_
|
Minimum log level to display (filters out lower levels).
Definition at line 141 of file LogWidget.ixx.
filterLevelIndex_
|
Current filter level selection index for the combo box.
Definition at line 151 of file LogWidget.ixx.
loggingDisabled_
|
Whether logging is completely disabled (None selected).
Definition at line 171 of file LogWidget.ixx.
maxEntries_
|
Maximum number of entries to retain per scope buffer.
Definition at line 96 of file LogWidget.ixx.
onScopeFilterChanged_
|
Callback function to notify external systems of scope filter changes.
Called when user selects a scope in the combo box. Signature: void(const std::string& scope) where empty string means "all".
Definition at line 179 of file LogWidget.ixx.
prevAutoScroll_
|
Previous autoScroll state to detect toggle events.
Definition at line 111 of file LogWidget.ixx.
scopeBuffers_
|
Per-scope log buffers. Key is scope name, value is entry vector.
Special key "__all__" contains all entries (for "All Scopes" view).
Definition at line 91 of file LogWidget.ixx.
scrollToBottom_
|
Flag to indicate that new content was added and scroll is needed.
Definition at line 121 of file LogWidget.ixx.
scrollUpOneEntry_
|
Flag to nudge scroll up one entry when auto-scroll is disabled.
Definition at line 116 of file LogWidget.ixx.
selectedScopeIndex_
|
Currently selected scope index in the combo box (0 = "All", -1 = "None").
Definition at line 161 of file LogWidget.ixx.
skippedEntries_
|
Counts how many log entries were skipped while logging was paused.
Definition at line 136 of file LogWidget.ixx.
textFilter_
|
Text filter for searching within log messages.
Definition at line 146 of file LogWidget.ixx.
wasAtBottom_
|
Tracks if user was at bottom in the previous frame.
Definition at line 126 of file LogWidget.ixx.
Private Static Functions
colorForLevel()
| inline nodiscard noexcept static |
Returns an ImVec4 color for the given log level.
- Parameters
-
level The log level to get a color for.
- Returns
The color corresponding to the log level.
Definition at line 231 of file LogWidget.ixx.
currentTimestamp()
| inline nodiscard noexcept static |
Generates a simple timestamp string (HH:MM:SS.mmm).
- Returns
The current time formatted as "HH:MM:SS.mmm".
Definition at line 263 of file LogWidget.ixx.
labelForLevel()
| inline nodiscard noexcept static |
Returns a string label for the given log level.
- Parameters
-
level The log level to get a label for.
- Returns
The label string (e.g., "[DEBUG]", "[INFO]").
Definition at line 248 of file LogWidget.ixx.
Private Static Attributes
ALL_SCOPES_KEY
| constexpr static |
Key for the "all scopes" combined view.
Definition at line 79 of file LogWidget.ixx.
NONE_SCOPES_KEY
| constexpr static |
Key for the "none" option that disables logging.
Definition at line 84 of file LogWidget.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.