LogPage.hpp

1. Overview

The LogPage.hpp header defines the LogPage class, a GTKmm (GTK4) UI component responsible for presenting application log output within the BastionGuard interface. The page provides a dedicated, scrollable text view that is periodically refreshed through a timer-driven update mechanism.

Functionally, LogPage provides:

  • A standalone page for displaying runtime and diagnostic logs
  • A Gtk::TextView-based interface for readable, selectable text output
  • An associated Gtk::TextBuffer for efficient content management
  • A periodic refresh callback compatible with GLib timeout signals

2. Dependencies and Includes

#include <gtkmm.h>
  • gtkmm.h – GTK4 C++ widgets, text components, and timer/signal infrastructure

3. Class Declaration and Scope

class LogPage : public Gtk::Box

The class derives from Gtk::Box, enabling it to be embedded as a page within notebooks, stacks, or container-based navigation systems.


4. Public Interface

4.1 Constructor

LogPage();

Constructs the log viewer page, initializes the text view and buffer, and configures the periodic refresh mechanism (implementation-defined).


5. UI Components

LogPage centers its interface around a single text display area backed by a reference-counted buffer.

5.1 Log Text View

Gtk::TextView textView;
  • textView – widget used to render log output in a scrollable, selectable, and copyable format
  • Supports monospaced fonts and wrapping policies (implementation-defined)

5.2 Text Buffer

Glib::RefPtr<Gtk::TextBuffer> buffer;

Reference-counted buffer that stores the current log contents and synchronizes updates with the Gtk::TextView.


6. Internal State and Data Model

The internal state of LogPage is minimal and consists primarily of:

  • The active Gtk::TextBuffer containing log data
  • The associated Gtk::TextView widget
  • The implicit timer state managed in the implementation file

7. User Actions and Callbacks

This header does not expose user-triggered callbacks. Log updates are managed internally through a periodic refresh mechanism.

7.1 Periodic Update Callback

bool update_logs();
  • update_logs() – refreshes the displayed log contents and returns a boolean value compatible with GLib signal_timeout semantics
  • A return value of true keeps the timer active, while false stops further invocations

8. Internal Logic

The main internal workflow revolves around periodically loading new log data and updating the text buffer. A typical implementation includes:

  • Reading from one or more log files or log streams
  • Appending or replacing buffer contents
  • Maintaining scroll position (e.g., auto-scroll to latest entries)
  • Handling file rotation or truncation gracefully

9. Auto-Update (Scheduled Refresh)

bool update_logs();

The update_logs() method is designed to be connected to a GLib timeout source. The refresh interval is defined in the corresponding implementation file and should balance responsiveness with resource usage.


10. Settings Storage

This header does not declare any settings persistence interface. Any user preferences (such as refresh rate, font size, or filtering rules) must be implemented externally or in the .cpp file.


11. Helper Functions and Filesystem Layout

No explicit filesystem helper functions are declared. The log file locations and access policies are expected to be defined by the surrounding application logic.


12. Runtime and Security Considerations

  • Non-blocking I/O: log file reads should be optimized to avoid blocking the GTK main loop; consider incremental or asynchronous reading strategies.
  • Access control: ensure that only authorized log files are opened and displayed to prevent unintended disclosure of sensitive information.
  • Content sanitization: treat log data as plain text to avoid unintended interpretation of escape sequences or markup.
  • Memory usage: large or long-running logs should be truncated or paged to prevent excessive memory consumption.
  • Timer lifecycle: ensure periodic callbacks are disconnected when the page is destroyed to avoid accessing invalid UI objects.