Introduction
The iloggui library provides Qt-based GUI components for visualizing and interacting with log messages from the ilog logging system. It offers rich visual display widgets, message box integration, and interactive log viewers with filtering, searching, and export capabilities. The library seamlessly integrates with the ACF component framework and Qt's widget system.
Key Features
- Interactive Log Viewer: QTreeWidget-based log display with multi-column layout
- Severity Filtering: Visual buttons for filtering by info/warning/error levels
- Text Search: Real-time search and filtering of log messages by content
- Message Export: Export log messages to files for analysis
- Message Boxes: Display critical messages in modal/non-modal dialog boxes
- Color-Coded Display: Icons and colors indicate message severity
- Timestamp Display: Configurable timestamp formatting for messages
- Diagnostic Mode: Optional diagnostic message collection and display
- Text-Based Log View: Rich text display with formatted message output
- Message Container Integration: Observes and displays messages from ilog::IMessageContainer
- Commands Integration: Provides toolbar/menu commands for log operations
- Hierarchical Messages: Support for hierarchical message organization
- Auto-Update: Real-time display updates when messages arrive
Architecture
The iloggui library contains three main GUI components:
CLogGuiComp
The primary log viewing component with full interactive features:
- iloggui::CLogGuiComp: Complete log viewer with filtering and commands
- Inherits from iqtgui::TDesignerGuiCompBase and ilog::CMessageContainer
- Implements ICommandsProvider for toolbar/menu integration
- Uses QTreeWidget for message display with columns:
- Icon column (severity indicator)
- Time column (message timestamp)
- Source column (message origin)
- Message column (message text)
- Filter modes: Info (all), Warning (warning+error+critical), Error (error+critical)
- Interactive features:
- Clear messages action
- Export to file action
- Diagnostic mode toggle
- Text filter with real-time search
- Column sorting
- Configuration attributes:
- MaxMessageCount: Limit on stored messages
- DefaultMode: Initial filter mode (0=info, 1=warning, 2=error)
- ShowLogDescription: Toggle log description visibility
- ShowMessageTextFilter: Toggle text filter widget
- ShowPanel: Toggle filter panel visibility
- AutoUpdateVisualStatus: Auto-update visual indicators
- TimeFormat: Custom timestamp format string
- AllowDiagnosticMessages: Enable diagnostic message collection
- Diagnostic state: Provides IEnableableParam interface for diagnostic control
- Slave consumer: Can delegate messages to another consumer
- File export: Integrated with ifile::IFilePersistence for export
CMessageBoxComp
Component for displaying messages in standard Qt message boxes:
- iloggui::CMessageBoxComp: Modal message box display
- Inherits from QObject, icomp::CComponentBase, and ilog::IMessageConsumer
- Displays messages in QMessageBox dialogs
- Automatic message queuing for sequential display
- Thread-safe message addition with QMutex
- Severity-based icons:
- Information icon for IC_INFO and IC_NONE
- Warning icon for IC_WARNING
- Critical icon for IC_ERROR and IC_CRITICAL
- Batches multiple messages into single dialog
- Creates detailed text from multiple queued messages
- Modal display (blocks until user acknowledges)
CTextLogGuiComp
Text-based log viewer with rich formatting:
- iloggui::CTextLogGuiComp: Rich text log display
- Inherits from iqtgui::TDesignerGuiObserverCompBase
- Observes ilog::IMessageContainer for changes
- Uses QTextEdit for formatted message display
- Displays messages in table format with:
- Category icon column
- Timestamp column
- Source column
- Message text column
- Filter controls:
- Severity level filter (info/warning/error/all)
- Source filter (text matching)
- Message text filter (content search)
- Configuration:
- IgnoreIdsList: Message IDs to exclude from display
- Real-time update when container changes
- Formatted text with custom table styling
- Read-only display (no editing)
Usage Examples
Creating a Log Viewer Window
- Configuration in .acc file
<Element Id="MainLog" ComponentId="ilog::CLogComp">
<AttributeInfo Id="MaxMessageCount"><Data IsEnabled="true" Value="5000"/></AttributeInfo>
</Element>
<Element Id="LogGuiWidget" ComponentId="iloggui::CLogGuiComp">
<AttributeInfo Id="MaxMessageCount"><Data IsEnabled="true" Value="5000"/></AttributeInfo>
<AttributeInfo Id="DefaultMode"><Data IsEnabled="true" Value="0"/></AttributeInfo>
<AttributeInfo Id="ShowMessageTextFilter"><Data IsEnabled="true" Value="true"/></AttributeInfo>
<AttributeInfo Id="TimeFormat"><Data IsEnabled="true" Value="hh:mm:ss.zzz"/></AttributeInfo>
</Element>
<Element Id="MainLog">
<Reference Id="SlaveMessageConsumer" Value="LogGuiWidget"/>
</Element>
- Programmatic Usage (with simulation layer)
#include <QtWidgets/QMainWindow>
QMainWindow* mainWindow = new QMainWindow;
QWidget* logWidget = logGui->GetWidget();
mainWindow->setCentralWidget(logWidget);
logComp->
SetRef(
"SlaveMessageConsumer", logGui);
1, "Application started", "Main")));
mainWindow->show();
bool SetBoolAttr(const QByteArray &attributeId, bool value)
Set instance of bool attribute.
bool SetRef(const QByteArray &referenceId, IComponentSharedPtr componentPtr, const QByteArray &subelementId="")
Set named reference to some component.
void InitComponent()
Initialilze component after setting all its attributes and references.
bool SetIntAttr(const QByteArray &attributeId, int value)
Set instance of int attribute.
bool SetStringAttr(const QByteArray &attributeId, const QString &value)
Set instance of QString attribute.
Basic implementation of the istd::IInformationProvider interface for log messages.
Shared ownership smart pointer for interface types.
Simple Message Box Display
- Configuration in .acc file
<Element Id="ErrorDialog" ComponentId="iloggui::CMessageBoxComp"/>
- Programmatic Usage (with simulation layer)
5001,
"Failed to connect to database",
"DatabaseManager"
)
);
messageBox->AddMessage(errorMsg);
5002,
"Network connection lost",
"NetworkManager"
)
);
messageBox->AddMessage(errorMsg2);
Both messages shown in single dialog with detailed text
Integrated Application Logging
centralLog->SetSlaveConsumer(consoleLog.get());
centralLog->AddMessage();
logViewer->AddMessage();
Console logging component with colored output.
Complete logging component with message storage and container interface.
Component that routes messages from one container to another with filtering.
Interactive log viewer component with filtering and commands.
Component for displaying log messages in modal Qt message boxes.
Text-Based Log Viewer
QWidget* logWidget = textLogViewer->GetWidget();
layout->addWidget(logWidget);
2001, "Data loaded successfully", "DataLoader")));
Text-based log viewer with rich formatting.
Using Log Commands
#include <QtWidgets/QToolBar>
QToolBar* toolbar = new QToolBar("Log Tools");
Common interface to define the hierarchical graph structures.
Exporting Log Messages
std::list< IMessageConsumer::MessagePtr > Messages
List type for storing message shared pointers.
Diagnostic Mode
Interface for objects which can be enabled/disabled.
virtual bool IsEnabled() const =0
Return true if something is enabled.
virtual bool SetEnabled(bool isEnabled=true)=0
Set the enabled state.
Custom Time Formatting
Hierarchical Log Containers
mainLog->AddChildContainer(networkLog.get());
mainLog->AddChildContainer(databaseLog.get());
Thread Safety
The iloggui components handle threading as follows:
- CLogGuiComp: Uses Qt signals/slots for thread-safe message addition
- Messages can be added from any thread
- GUI updates always occur on GUI thread via EmitAddMessage signal
- Message container operations are protected
- CMessageBoxComp: Uses QMutex to protect message queue
- Messages can be added from any thread
- Dialog display occurs on GUI thread via EmitAddMessage signal
- Queue access is synchronized
- CTextLogGuiComp: Inherits model-observer thread safety
- Updates triggered by model change notifications
- GUI updates occur on GUI thread
- Observer pattern handles thread transitions
- Warning
- Always create GUI components on the main GUI thread. Only message addition (AddMessage) is thread-safe; other operations should be performed on the GUI thread.
Visual Styling
The iloggui components use standard Qt styling:
Message Icons
Icons indicate message severity:
- Info/None: Information icon (blue "i")
- Warning: Warning icon (yellow triangle with "!")
- Error: Error icon (red "X")
- Critical: Critical icon (red stop sign)
Icons are platform-specific Qt standard pixmaps for consistent look.
Color Coding
CLogGuiComp uses color coding:
- Info messages: Default color
- Warning messages: Yellow/amber highlighting
- Error messages: Red highlighting
- Critical messages: Dark red highlighting
Colors adapt to Qt style and platform theme.
ACF Component Integration
The iloggui components integrate with ACF framework:
- Component References: Use I_REF macros for dependencies
- SlaveMessageConsumer: Delegate messages
- Exporter: File export handler
- InputMessageContainer: Source for routing
- Model: Container to observe
- Component Attributes: Use I_ATTR macros for configuration
- MaxMessageCount, DefaultMode, TimeFormat, etc.
- Serializable for persistence
- Observable for real-time updates
- Subelements: CLogGuiComp provides DiagnosticState subelement
- Accessible as IEnableableParam
- Serializable and changeable
- Integrated with model system
- Interface Registration: Implement standard ACF interfaces
- IMessageConsumer for receiving messages
- ICommandsProvider for toolbar/menu integration
- IMessageContainer for message storage
Dependencies
The iloggui library depends on:
- ilog: Logging framework (IMessageConsumer, IMessageContainer, CMessage, CMessageContainer)
- iqtgui: Qt GUI framework (TDesignerGuiCompBase, CHierarchicalCommand, CGuiComponentBase)
- icomp: Component framework (CComponentBase, IComponent)
- imod: Model-observer (IModel, IObserver, CSingleModelObserverBase)
- iprm: Parameters (IEnableableParam, CEnableableParam)
- ibase: Base interfaces (ICommandsProvider, IHierarchicalCommand)
- ifile: File operations (IFilePersistence)
- istd: Standard utilities (IChangeable, smart pointers)
- Qt Widgets: QTreeWidget, QTextEdit, QMessageBox, QAction, QIcon
- Qt Core: QString, QDateTime, QVector, QMutex
- Qt GUI: QIcon, QImage, QTextDocument
Best Practices
- Use CLogGuiComp for Main Window: Best for primary application log display
- Use CMessageBoxComp for Critical Errors: Alert users to critical issues immediately
- Use CTextLogGuiComp for Read-Only Views: Good for simple log display without interaction
- Configure Maximum Messages: Prevent memory issues in long-running applications
- Set Appropriate Default Mode: Start with appropriate filter level (errors for production)
- Enable Text Filter: Allow users to search log content
- Provide Export Capability: Let users save logs for support and debugging
- Use Hierarchical Containers: Organize logs by subsystem or component
- Configure Time Format: Match user locale and preferences
- Integrate Commands: Add log commands to main toolbar/menu for accessibility
- Handle Message Overflow: Configure MaxMessageCount and consider log rotation
- Test Thread Safety: Ensure messages from worker threads display correctly
- Style Appropriately: Use Qt stylesheets to match application theme
- Provide Clear Action: Make clear/export actions easily accessible
- Consider Performance: With many messages, filtering and scrolling may slow down
See Also
Logging Components
ilog Library
Qt Classes
- QTreeWidget
- QTextEdit
- QMessageBox
- QAction