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

#include <EvlogParser.hpp>

Inheritance diagram for parser::EvlogParser:
Inheritance graph
Collaboration diagram for parser::EvlogParser:
Collaboration graph

Public Types

enum  Format : int32_t { NODATA = 0 , BINARY = 1 , STRING = 2 , PRINTF = 3 }
 Payload encoding constants (log_format field). More...
 

Public Member Functions

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.
 
util::Result< void, error::Error > SetTemplateDirectory (const std::filesystem::path &dir)
 
void SetTemplateFile (const std::filesystem::path &path)
 Load a single template file. May be called multiple times.
 
virtual std::vector< std::pair< std::string, std::string > > GetFileMetadata () const
 Ordered key → value pairs read from the file header during the last ParseData() call (see db::EventsContainer::SetFileMetadata).
 
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)
 

Private Member Functions

util::Result< int, error::Error > ParseStream (std::istream &input)
 

Private Attributes

uint32_t m_currentProgress {0}
 
uint32_t m_totalProgress {0}
 
int m_eventId {0}
 
std::unique_ptr< EvlogTemplateRegistry > m_registry
 
std::vector< IDataParserObserver * > observers
 

Detailed Description

Parser for Linux Enterprise Event Logging (evlog) binary files.

Implements a self-contained reader for the POSIX 1003.25 evlog binary format as produced by the evlogd daemon (evlog.sourceforge.net).

File format

A flat stream of variable-length records with no file-level header. Each record consists of:

  • A 60-byte fixed header (posix_log_entry, 32-bit little-endian layout)
  • log_size bytes of variable payload (may be 0)

Fixed header layout (all little-endian)

Offset Size Field 0 4 log_recid — record serial number 4 4 log_size — bytes of payload following this header 8 4 log_format — payload encoding (see Format enum) 12 4 log_event_type — application-defined event type 16 4 log_facility — syslog facility code (LOG_USER=8, …) 20 4 log_severity — syslog severity (0=EMERG … 7=DEBUG) 24 4 log_uid — real UID of logging process 28 4 log_gid — real GID of logging process 32 4 log_pid — PID 36 4 log_pgrp — process group ID 40 4 log_time.tv_sec — UNIX timestamp (seconds) 44 4 log_time.tv_nsec— sub-second nanoseconds 48 4 log_flags — EVL_* flag bits 52 4 log_thread — pthread_t (32-bit value) 56 4 log_processor — CPU number

Payload encoding (log_format values)

0 NODATA — no payload (log_size should be 0) 1 BINARY — raw binary blob; emitted as hex dump 2 STRING — null-terminated UTF-8/ASCII string; emitted as info 3 PRINTF — null-terminated format string + binary varargs; format string is extracted as info, varargs as hex

Emitted event fields

timestamp — float seconds (tv_sec.tv_nsec) level — Emergency|Alert|Critical|Error|Warning|Notice|Info|Debug facility — kern|user|mail|daemon|auth|syslog|lpr|news|uucp| cron|authpriv|ftp|local0…local7|unknown event_type — hex string (e.g. "0x00000001") pid — decimal PID uid — decimal UID flags — comma-separated EVL flag names (omitted if none set) recid — decimal record ID cpu — decimal CPU number (omitted if 0) info — decoded payload text

Member Enumeration Documentation

◆ Format

Payload encoding constants (log_format field).

Enumerator
NODATA 
BINARY 
STRING 
PRINTF 

Member Function Documentation

◆ GetCurrentProgress()

uint32_t parser::EvlogParser::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()

virtual std::vector< std::pair< std::string, std::string > > parser::IDataParser::GetFileMetadata ( ) const
inlinevirtualinherited

Ordered key → value pairs read from the file header during the last ParseData() call (see db::EventsContainer::SetFileMetadata).

Returns
Empty for formats without a header (the default).

Reimplemented in parser::SapiLogParser.

◆ GetTotalProgress()

uint32_t parser::EvlogParser::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.

◆ 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::EvlogParser::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::EvlogParser::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.

Here is the call graph for this function:

◆ ParseStream()

util::Result< int, error::Error > parser::EvlogParser::ParseStream ( std::istream &  input)
private

Parse all records from input. Returns the number of records emitted on success, or an error if the stream yields zero bytes on the very first header read.

Here is the call graph for this function:
Here is the caller 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

◆ SetTemplateDirectory()

util::Result< void, error::Error > parser::EvlogParser::SetTemplateDirectory ( const std::filesystem::path &  dir)

Load all *.t/*.tmpl/*.template files from dir and use them to decode BINARY payloads. Must be called before ParseData(). Returns Err if the directory cannot be iterated (e.g. does not exist).

Here is the call graph for this function:

◆ SetTemplateFile()

void parser::EvlogParser::SetTemplateFile ( const std::filesystem::path &  path)

Load a single template file. May be called multiple times.

Here is the call graph for this function:

◆ UnregisterObserver()

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

Member Data Documentation

◆ m_currentProgress

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

◆ m_eventId

int parser::EvlogParser::m_eventId {0}
private

◆ m_registry

std::unique_ptr<EvlogTemplateRegistry> parser::EvlogParser::m_registry
private

◆ m_totalProgress

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

◆ observers

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

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