|
LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
|
LogViewer is a professional log file viewer application built with modern C++20 and Qt 6, following clean architecture principles and industry-standard design patterns. The application provides powerful AI-assisted log analysis, flexible filtering, and a highly customizable dock-based UI.
The Qt UI layer is structured into four subdirectories under src/application/ui/qt/:
| Subdirectory | Contents |
|---|---|
panels/ | All dock and content panels (FiltersPanel, StatsSummaryPanel, SignalPlotPanel, TimelineChartPanel, TraceViewerPanel, TestStepsPanel, BookmarksPanel, ScenariosPanel, ActorsPanel, PatternAnalysisPanel, SideBySidePanel, …) |
dialogs/ | Dialogs (ConfigEditorDialog, FilterEditorDialog, LogFileLoadDialog, UpdateDialog, …; RunExplorerDialog is non-modal) |
events/ | Event table model and view (EventsTableModel, EventsTableView), Excel-style column value filters (ColumnFilterPopup, FilterHeaderView) |
utils/ | Shared utilities (PanelUtils, ThemeSwitcher, ExportManager, TypeFilterView, UpdateChecker) |
MainWindow: Central orchestrator
QDockWidget each); right dock: Details; bottom dock: AI chat / plugin panelsConfigObserver and IPluginObserver for configuration and plugin lifecycle changesCreateParserFor() produces format-specific pre-configured parsers: AscParser with DBC path for .asc; EvlogParser with template directory for .evl; ParserFactory for all other typesEventsTableView: High-performance table display (events/)
typeFilterFieldAnalysis Panels (panels/)
IStatisticsStrategy (see below)SIG:* field values over time; QLineSeries per signal; downsamples to 2 000 points. Signal selection is delegated to CanSignalTreePanel — the plot has no embedded tree.SetDatabase(DbcDatabase) when a DBC is loaded. Emits SignalSelectionChanged → wired to SignalPlotPanel::SetSelectedSignals().analyzer::BuildTestOutline() as a QTreeWidget (sections → keywords/expectations: status, start, duration, events) under a PASS/FAIL banner with the failing step, its message and Go to failure. Double-click/Enter or the button emit NavigateToEvent(row), which MainWindow routes like a bookmark (Events page + ScrollToActualRow). Refreshed lazily like the other analysis panels, but re-analyses only when the data changes (container generation, size, file metadata) — the outline covers the whole log, not the filtered rows. Logs without TEST_START show a hint.dialogs/): non-modal window opened by File → Open Results Folder… (Ctrl+Alt+O) or by dropping a folder (MainWindow::OpenResultsFolder). A dialog rather than a dock: the table needs width for the failure messages, it stays open beside the main window while logs are opened from it, and no dock layout/state changes. It runs analyzer::ScanResultsFolder() through QtConcurrent::run with a QPromise (progress bar, Cancel, a new folder cancels the running scan) and shows the entries in a QTreeWidget: sortable columns, a verdict filter, and "Group failures by message" (analyzer::GroupFailures, groups as parent rows). Activating a test emits OpenTestRequested(path) → MainWindow::OpenTestLog → ReplaceWithFile() (the same path as Open: CreateParserFor, StopTailing, LoadLogFile, recent files). "Open with Previous Test" emits OpenWithPreviousRequested with entry i − 1 (entries are in run order, whatever the view's sort) → ReplaceWithFile(previous) + MergeLogFile(test) with the test names as aliases.Configuration Dialogs (dialogs/)
MainWindowPresenter: MVP pattern implementation
typeFilterField for type filteringAIServiceFactory: Creates appropriate AI clients
LogAnalyzer: AI analysis orchestration
ParserFactory: Creates appropriate parsers
Registered parsers (extension → class):
| Extension | Parser | Notes |
|---|---|---|
.xml | XmlParser | Default for unknown extensions |
.csv | CsvParser | |
.json / .jsonl | JsonParser | JSON array or NDJSON; nested objects flattened with dot notation |
.asc | AscParser | CAN/Vector CANalyzer; constructed with optional DBC path via CreateParserFor() |
.dlt | DltParser | AUTOSAR Diagnostic Log and Trace binary |
.evl | EvlogParser | POSIX 1003.25 evlog binary; constructed with optional template directory via CreateParserFor() |
.txt (sniffed) / .sapilog | SapiLogParser | safeAPI RBC 2oo2 merged test log; ParserFactory maps .txt to it only when the # FULL MERGED TEST STEPS header is present, otherwise .txt keeps the existing fallback/prompt |
JsonParser (parsers/json/): Parses JSON log files in two layouts.
nlohmann::json parser callback that flattens and discards each top-level element as it completes (bounded memory), emitting events in batches.WARN log entry.[ → array, { → NDJSON).ctx.host) and index suffixes (tags.0, tags.1), respectively.AscParser (parsers/asc/): Parses Vector CANalyzer .asc files line by line.
LogEvent with fields: timestamp (float seconds), type (Rx/Tx/TxRq/ErrorFrame), CAN_ID (hex), CAN_Channel, CAN_DLC, CAN_Data (hex bytes), CAN_IDE (Standard/Extended), info.CanDecoder is invoked per-frame to append SIG:<name> fields for every decoded signal.DbcParser + CanDecoder (parsers/dbc/): Reads .dbc CAN database files.
ParseDbcFile() returns a DbcDatabase containing a map of message ID → DbcMessage (name, signals).DecodeFrame() applies Intel (little-endian) or Motorola (big-endian) bit extraction to produce {"SIG:<name>", "<value>"} pairs.DltParser (parsers/dlt/): Parses AUTOSAR DLT binary files (.dlt).
DLT\x01 magic (16-byte: magic + timestamp + ECU ID).MsgID=0x… + hex dump.timestamp, level (Off/Fatal/Error/Warn/Info/Debug/Verbose), type (Log/AppTrace/NwTrace/Control), AppID, ContextID, EcuID, MsgCtr, optional SessionID, info.SapiLogParser (parsers/sapi/): Parses merged test-run logs from the safeAPI RBC 2oo2 test environment (robot steps + container + simulator logs).
# lines (its # Key : Value lines — Test Case, Status, Timestamp, Sources, Entries — are returned by GetFileMetadata(), an IDataParser virtual that is empty for other formats; MainWindowPresenter::RunParserAsync stores them with EventsContainer::SetFileMetadata()), then one event per line: [timestamp] [category] [source] [destination] [level] [event type] [info] [payload].info/payload); payload is the remainder after the 7th field, multiple groups kept verbatim. Malformed lines are skipped; a file with no matching line throws ParseError.timestamp (ISO-8601 string), category, source, destination, level, event_type, info, optional payload, optional unit, optional p.<key> payload fields.unit: the 2oo2 channel from an info prefix [unit | partition] ([a-west | GP] … → a-west, also | RTE); source alone says RBC West for both channels. Extracted by SapiLogParser::ExtractUnit().SapiLogParser::ExtractPayloadFields()): the raw payload is kept and its structured content is added as p.<key> fields. A JSON object ({"cmd": "getMessage", "nidEngine": 1}, parsed with nlohmann::ordered_json, source order kept) gives p.cmd, p.nidEngine; members of a nested object become p.<key>.<member> (p.fields.route_len), anything deeper stays compact JSON text. A payload made only of key=value tokens (cycle=415 level=INFO site=WEST unit=GW-CTC/WEST up=1) gives p.cycle, p.level, …; values may be quoted or hold balanced [...]/{...}, bracket groups of pairs ([train_id=1] [P0] [cycle=2 …]) are unwrapped and single-word label groups skipped. Values are kept verbatim, including real-log quirks such as CRC=OK).key=value token is enough), invalid JSON and unbalanced brackets yield no fields; payloads over 4 KiB are skipped; at most 32 fields per event; keys over 64 or values over 512 characters and repeated keys (first wins) are dropped.SapiLogParser::LooksLikeSapiLog() sniffs the header so generic .txt files are auto-routed here (in ParserFactory::CreateFromFile and MainWindow::CreateParserFor); the file-type prompt also lists it (.sapilog).EvlogParser (parsers/evlog/): Parses POSIX 1003.25 evlog binary files (.evl).
posix_log_entry header at known byte offsets; no file-level magic (sanity-checked via severity ≤ 7 and format ∈ {0,1,2,3}).NODATA (no payload), STRING (null-terminated UTF-8), PRINTF (format string + binary varargs shown as hex), BINARY (template-decoded or hex dump).timestamp (float seconds), level (Emergency→Debug), facility (kern/user/…/local7), event_type (hex), pid, uid, recid, optional cpu (if ≠ 0), flags (comma-separated EVL_* names if set), info.SetTemplateDirectory(path) or SetTemplateFile(path) before ParseData() to enable template-based BINARY decoding.EvlogTemplateRegistry (parsers/evlog/): Loads and indexes evlog template files.
.t, .tmpl, .template files; parses each with a state-machine line reader.facility, event_type, description, attributes { typed-fields }, format "…%name%…" keywords (also supports keyword% evlog-native form; #/// comments; --- record separator).char[N], variable string.Find(facility, eventType) returns the matching EvlogTemplate* or nullptr; lookup is O(log n) via std::map.SideBySidePanel (panels/): Displays two independently-loaded log files in a vertical splitter with a shared toolbar for synchronisation control.
rightTs = leftTs + offset is computed and used for all subsequent lookups), None (views independent).EventsContainer and EventsTableView; file loading runs on a background thread via QtConcurrent::run and QFutureWatcher<void>.LoadJob::Observer struct adapts IDataParserObserver callbacks to EventsContainer::AddEvent()/AddEventBatch() without the panel needing to implement the observer interface itself.SuspendNotifications()/ResumeNotifications() are called around bulk loads to suppress per-batch UI redraws.m_syncInProgress flag that prevents left-select → scroll right → right-select → scroll left loops.timestamp field) fall back to a row-offset arithmetic approximation based on the proportional position of the reference row.MainWindow::RunAsyncFilter(worker, statusMsg) encapsulates the QFutureWatcher setup, progress bar, and in-progress guard so ApplyExtendedFilters() and ApplyActorFilter() share a single implementation.Statistics Strategy (ui/qt/panels/): The StatsSummaryPanel uses IStatisticsStrategy to compute format-specific metrics at refresh time without coupling the panel to any particular format.
SelectStrategy() probes the first 20 events for CAN_ID to pick the right implementation. Adding a new format requires only implementing IStatisticsStrategy::Matches() and Compute().
TestOutline (analyzers/TestOutline.{hpp,cpp}, no Qt): analyzer::BuildTestOutline(events, TestMarkerRules) turns a test-harness log into steps, the verdict and the decisive failure. TestMarkerRules holds the event vocabulary (defaults: the Robot Framework listener lines of safeAPI merged logs — TEST_START/TEST_END, STEP, STEP_FAIL, LOG markers TestStep N:/TestExpectation …, Control command sent).
TestStep marker), one per TestStep marker, Teardown (keywords after the last marker when it is a TestExpectation); children are the keywords (one per STEP) and expectations. Durations run until the next step starts (the listener logs no keyword end or nesting depth).STEP_FAIL belongs to the latest not-yet-failed STEP of that keyword; it is recovered when the same keyword with the same arguments starts again later (retry) or the test passed. In real logs 1,610 of 2,003 STEP_FAILs are in PASS logs.Status, else (PASS)/(FAIL) in TEST_END. Decisive failure: the first unrecovered STEP_FAIL (the innermost keyword of the failing chain, not a later teardown failure), else TEST_END (suite-setup failures leave only TEST_START/TEST_END).TestRunIndex (analyzers/TestRunIndex.{hpp,cpp}, no widgets; QtCore only for QXmlStreamReader): the tests of one results folder (*__merged_logs.txt, not recursive) for the Run Explorer.
ReadTestLogSummary(): the # header (decoded line by line with SapiLogParser::ParseHeaderLine, so the keys match the file metadata of a loaded log: Test Case, Status, Timestamp, Entries), the first event line and the last 64 KiB of the file for the first/last timestamps (duration). Events are never parsed.FindDecisiveFailureMessage() (FAIL logs only): one line scan that parses only lines carrying [TEST_START], [TEST_END], [STEP] or [STEP_FAIL] and feeds them to BuildTestOutline, so the message is the one the Test Steps banner shows. About 0.9 s for a run of 49 failed logs (55 MB); PASS logs cost a few ms.ReadRobotFailures(): for FAIL logs without a failing step (suite-setup failures) — xunit.xml <testcase name> → <failure message>/<error message>, or when there is no readable xunit.xml, output.xml (the FAIL <status> text that is a direct child of <test>). Names are matched by TestNameKey() (lower-case letters and digits), so header names, Robot names and file names agree.ScanResultsFolder(): all of the above with a progress/cancel callback; the result is sorted by header Timestamp (else first event), so the test before entry i is entry i − 1. GroupFailures() groups FAIL messages by NormalizeFailureMessage() (whitespace collapsed, digit runs → N), largest group first.FilterManager: Coordinates filtering operations
Config: Centralized configuration management
typeFilterField: Field used for type filtering/coloring — auto-detected on each file load; leave empty (default) to auto-detect, or set explicitly to pin a value for all filesaiProvider: AI service provider selectionaiTimeoutSeconds: Configurable timeout for AI requests (30-3600s)EventsContainer: High-performance event storage
IModel interfaceSetFileMetadata()/GetFileMetadata() keep the parser's header pairs (cleared by Clear(), kept by MergeEvents())LogEvent: Immutable event representation
findByKey() method for dynamic field accessPurpose: Abstract creation of parsers and AI clients
ParserFactory: Creates appropriate parser based on file extension
AIServiceFactory: Creates appropriate AI client based on provider
Benefits:
Purpose: Pluggable algorithms for filtering and AI providers
Filter Strategies:
AI Service Interface:
Benefits:
Purpose: Decouple components and enable reactive UI
ConfigObserver: React to configuration changes
Benefits:
Purpose: Separate data, presentation, and control logic
EventsContainer, LogEvent): Data and business logicMainWindow, EventsTableView, dock widgets): Presentation and rendering MainWindowPresenter): Coordinates between view and model, handles user actionsBenefits:
AI providers are implemented as C-ABI plugins (see PLUGIN_SYSTEM.md):
Plugin Exports:
Plugin_Create() - Creates plugin instancePlugin_SetLoggerCallback(handle, logFn) - Receives logging callbackPlugin_CreateAIService(handle, settings) - Creates AI servicePlugin_CreateMainPanel(handle, parent, settings) - Analysis panelPlugin_CreateLeftPanel(handle, parent, settings) - Configuration panelPlugin_CreateBottomPanel(handle, parent, settings) - Chat panelBenefits:
GetFilteredIndices() methodfilteredIndices parameterFor large datasets:
QtConcurrent for AI requests in background threadModern error handling without exceptions in hot paths:
findByKey() for flexible event schemasAll configuration saved to platform-specific location:
~/Library/Application Support/LogViewer/config.json~/.config/LogViewer/config.jsonAPPDATA%\LogViewer\config.jsonNote on XML parsing: The XML parser uses element depth to discover structure automatically — no
rootElementoreventElementconfiguration is needed. The first element at depth 1 is treated as the root; every direct child (depth 2) is an event record; nested children (depth 3+) become key/value fields.
level, type, severity, priority, category, …). Set explicitly (in Settings > General) to pin a value and skip auto-detection. Leave empty to always auto-detect; if detection fails the user is prompted.Components register for configuration changes: