LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
Loading...
Searching...
No Matches
parser::SapiLogParser Class Reference

Parses merged test-run logs produced by the safeAPI RBC 2oo2 test environment (robot steps + container + simulator logs in one file). More...

#include <SapiLogParser.hpp>

Inheritance diagram for parser::SapiLogParser:
Inheritance graph
Collaboration diagram for parser::SapiLogParser:
Collaboration graph

Public Member Functions

 SapiLogParser ()=default
 
 ~SapiLogParser () override=default
 
void ParseData (const std::filesystem::path &filepath) override
 Parses data from a file path.
 
void ParseData (std::istream &input) override
 Parses data from an input stream.
 
uint32_t GetCurrentProgress () const override
 Gets the current parsing progress.
 
uint32_t GetTotalProgress () const override
 Gets the total expected progress value.
 
std::vector< std::pair< std::string, std::string > > GetFileMetadata () const override
 
void RegisterObserver (IDataParserObserver *observer)
 Registers an observer to receive parsing notifications.
 
void UnregisterObserver (IDataParserObserver *observer)
 
void NotifyNewEvent (db::LogEvent &&event)
 
void NotifyProgressUpdated ()
 
void NotifyNewEventBatch (std::vector< std::pair< int, db::LogEvent::EventItems > > &&eventBatch)
 

Static Public Member Functions

static bool LooksLikeSapiLog (const std::filesystem::path &filepath)
 
static bool ParseLine (std::string_view line, db::LogEvent::EventItems &out)
 
static void ParseHeaderLine (std::string_view line, std::vector< std::pair< std::string, std::string > > &metadata)
 
static std::string_view ExtractUnit (std::string_view info)
 
static void ExtractPayloadFields (std::string_view payload, db::LogEvent::EventItems &out)
 

Private Member Functions

void ParseStream (std::istream &input)
 

Private Attributes

uint32_t m_currentProgress {0}
 
uint32_t m_totalProgress {0}
 
std::vector< std::pair< std::string, std::string > > m_metadata
 
std::vector< IDataParserObserver * > observers
 

Detailed Description

Parses merged test-run logs produced by the safeAPI RBC 2oo2 test environment (robot steps + container + simulator logs in one file).

File layout: a #-prefixed header block, then one event per line, each field wrapped in square brackets:

[timestamp] [category] [source] [destination] [level] [event type] [info] [payload]

Brackets may nest inside info and payload (e.g. [[ 419310003] [GW-IL EAST] starting]), so fields are split by bracket depth, not by a fixed regex. payload is everything after the 7th field; it may hold several bracket groups ([train_id=1] [P0] [cycle=1 ...]) — those are kept verbatim.

Parsed LogEvent fields: timestamp — ISO-8601 UTC string, unchanged (e.g. "2026-09-19T06:46:46.456779Z") category — "GENERAL" or "IO" source — emitting component (e.g. "a-west", "robot", "il-multi") destination — target component(s) or "internal" level — INFO / DEBUG / ERROR / FAIL event_type — LOG, STEP, ENVELOPE, CMD_RESP, ... info — short description payload — trailing data (omitted when empty) unit — 2oo2 channel from an info prefix like [a-west | GP] … (optional) p.<key> — structured payload content, see ExtractPayloadFields() (optional)

The header's # Key : Value lines are not events; they are available through GetFileMetadata() after parsing.

Lines that do not match the layout are skipped. If no line matches at all, ParseData() throws error::Error(ParseError) so a wrong file-type choice is reported instead of silently producing an empty view.

Constructor & Destructor Documentation

◆ SapiLogParser()

parser::SapiLogParser::SapiLogParser ( )
default

◆ ~SapiLogParser()

parser::SapiLogParser::~SapiLogParser ( )
overridedefault

Member Function Documentation

◆ ExtractPayloadFields()

void parser::SapiLogParser::ExtractPayloadFields ( std::string_view  payload,
db::LogEvent::EventItems &  out 
)
static

Appends the structured content of payload to out as p.<key> fields. The raw payload is never modified. Recognised shapes:

  • a JSON object: top-level values become p.<key>, members of a nested object p.<key>.<member>; strings are unquoted, anything deeper is kept as compact JSON text;
  • whitespace-separated key=value tokens (values may be quoted or hold balanced [...]/{...}); bracket groups of such tokens are unwrapped and single-word label groups ([P0]) are ignored. Anything else — free text, a single non-key=value token, invalid JSON, unbalanced brackets — yields no fields. Bounded per event: payloads over 4 KiB are skipped, at most 32 fields, over-long keys/values and repeated keys are dropped (first occurrence wins).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExtractUnit()

std::string_view parser::SapiLogParser::ExtractUnit ( std::string_view  info)
static

Returns the unit of an info field that starts with a [unit | partition] marker (e.g. "a-west" for [a-west | GP] Log message), else an empty view.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCurrentProgress()

uint32_t parser::SapiLogParser::GetCurrentProgress ( ) const
inlineoverridevirtual

Gets the current parsing progress.

Returns
uint32_t Current progress value (meaning depends on implementation)
Note
Progress values should be used with GetTotalProgress() for percentage calculations

Implements parser::IDataParser.

◆ GetFileMetadata()

std::vector< std::pair< std::string, std::string > > parser::SapiLogParser::GetFileMetadata ( ) const
inlineoverridevirtual

The # Key : Value lines of the header block (before the first event), in file order, e.g. {"Test Case", "IL Grants A Movement Authority"}, {"Status", "PASS"}, {"Timestamp", …}, {"Sources", …}, {"Entries", "1129"}.

Reimplemented from parser::IDataParser.

◆ GetTotalProgress()

uint32_t parser::SapiLogParser::GetTotalProgress ( ) const
inlineoverridevirtual

Gets the total expected progress value.

Returns
uint32_t Maximum progress value when parsing is complete
Note
Return 0 if total progress cannot be determined in advance

Implements parser::IDataParser.

◆ LooksLikeSapiLog()

bool parser::SapiLogParser::LooksLikeSapiLog ( const std::filesystem::path &  filepath)
static

True when the first lines of filepath carry the merged-log header (# FULL MERGED TEST STEPS, CONTAINER & SIMULATOR LOGS). Used to auto-select this parser for generic .txt files.

Here is the caller graph for this function:

◆ NotifyNewEvent()

void parser::IDataParser::NotifyNewEvent ( db::LogEvent &&  event)
inlineinherited

◆ NotifyNewEventBatch()

void parser::IDataParser::NotifyNewEventBatch ( std::vector< std::pair< int, db::LogEvent::EventItems > > &&  eventBatch)
inlineinherited
Here is the caller graph for this function:

◆ NotifyProgressUpdated()

void parser::IDataParser::NotifyProgressUpdated ( )
inlineinherited
Here is the caller graph for this function:

◆ ParseData() [1/2]

void parser::SapiLogParser::ParseData ( const std::filesystem::path &  filepath)
overridevirtual

Parses data from a file path.

Parameters
filepathThe path to the file to parse
Exceptions
std::runtime_errorif the file cannot be opened or parsed
Note
This method should be implemented by derived classes for file-based parsing

Implements parser::IDataParser.

Here is the call graph for this function:

◆ ParseData() [2/2]

void parser::SapiLogParser::ParseData ( std::istream &  input)
overridevirtual

Parses data from an input stream.

Parameters
inputThe input stream to read data from
Exceptions
std::runtime_errorif the stream cannot be read or parsed
Note
This method enables parsing from various sources (files, network, memory)

Implements parser::IDataParser.

◆ ParseHeaderLine()

void parser::SapiLogParser::ParseHeaderLine ( std::string_view  line,
std::vector< std::pair< std::string, std::string > > &  metadata 
)
static

Appends a header line such as # Test Case : IL Grants … (starting with '#') to metadata as {"Test Case", "IL Grants …"}; other comment lines (rulers, the title line) are ignored.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParseLine()

bool parser::SapiLogParser::ParseLine ( std::string_view  line,
db::LogEvent::EventItems &  out 
)
static

Parses one line into out. Returns false for header, blank and malformed lines. Exposed for tests.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParseStream()

void parser::SapiLogParser::ParseStream ( std::istream &  input)
private
Here is the call graph for this function:

◆ RegisterObserver()

void parser::IDataParser::RegisterObserver ( IDataParserObserver *  observer)
inlineinherited

Registers an observer to receive parsing notifications.

Parameters
observerPointer to the observer object
Note
The observer must remain valid until parsing completes or it's unregistered
Duplicate observers are automatically prevented

◆ UnregisterObserver()

void parser::IDataParser::UnregisterObserver ( IDataParserObserver *  observer)
inlineinherited

Member Data Documentation

◆ m_currentProgress

uint32_t parser::SapiLogParser::m_currentProgress {0}
private

◆ m_metadata

std::vector<std::pair<std::string, std::string> > parser::SapiLogParser::m_metadata
private

◆ m_totalProgress

uint32_t parser::SapiLogParser::m_totalProgress {0}
private

◆ observers

std::vector<IDataParserObserver*> parser::IDataParser::observers
privateinherited

The documentation for this class was generated from the following files: