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

#include <FileTailer.hpp>

Inheritance diagram for ui::qt::FileTailer:
Inheritance graph
Collaboration diagram for ui::qt::FileTailer:
Collaboration graph

Classes

struct  TailObserver
 

Signals

void NewEventsAvailable (std::size_t count)
 Emitted on the main thread after new events have been added.
 
void TailingError (const QString &message)
 Emitted when a tailing read or parse error occurs.
 

Public Member Functions

 FileTailer (QObject *parent=nullptr)
 
 ~FileTailer () override=default
 
void Start (const std::filesystem::path &path, std::unique_ptr< parser::IDataParser > parser, db::EventsContainer &events)
 
void Stop ()
 
bool IsActive () const
 
const std::filesystem::path & FilePath () const
 

Private Slots

void OnFileChanged (const QString &path)
 

Private Attributes

QFileSystemWatcher m_watcher
 
std::unique_ptr< parser::IDataParser > m_parser
 
std::unique_ptr< TailObserver > m_observer
 
db::EventsContainer * m_events {nullptr}
 
std::filesystem::path m_path
 
uintmax_t m_lastOffset {0}
 
bool m_active {false}
 
bool m_lineBased {true}
 

Detailed Description

Watches a log file for new content and incrementally parses appended bytes.

After construction call Start(); the tailer attaches a QFileSystemWatcher to the given path. Each time the file grows the new bytes are extracted and fed to the parser's ParseData(istream&) overload. The supplied EventsContainer receives the new events via the parser's observer mechanism.

Supported formats (line- or record-based parsers that accept a partial stream starting mid-file): NDJSON/JSONL, CAN/ASC, AUTOSAR DLT

Unsupported formats: JSON array (whole-document), XML (stateful), CSV (header in first line). For these formats Start() will emit TailingError.

The parser instance is owned externally and must outlive FileTailer.

Constructor & Destructor Documentation

◆ FileTailer()

ui::qt::FileTailer::FileTailer ( QObject *  parent = nullptr)
explicit
Here is the call graph for this function:

◆ ~FileTailer()

ui::qt::FileTailer::~FileTailer ( )
overridedefault

Member Function Documentation

◆ FilePath()

const std::filesystem::path & ui::qt::FileTailer::FilePath ( ) const
inline

◆ IsActive()

bool ui::qt::FileTailer::IsActive ( ) const
inline

◆ NewEventsAvailable

void ui::qt::FileTailer::NewEventsAvailable ( std::size_t  count)
signal

Emitted on the main thread after new events have been added.

Here is the caller graph for this function:

◆ OnFileChanged

void ui::qt::FileTailer::OnFileChanged ( const QString &  path)
privateslot
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Start()

void ui::qt::FileTailer::Start ( const std::filesystem::path &  path,
std::unique_ptr< parser::IDataParser >  parser,
db::EventsContainer &  events 
)

Begin watching path, parsing new bytes with parser into events. Emits TailingError immediately if the format is known-unsupported.

Here is the call graph for this function:

◆ Stop()

void ui::qt::FileTailer::Stop ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TailingError

void ui::qt::FileTailer::TailingError ( const QString &  message)
signal

Emitted when a tailing read or parse error occurs.

Here is the caller graph for this function:

Member Data Documentation

◆ m_active

bool ui::qt::FileTailer::m_active {false}
private

◆ m_events

db::EventsContainer* ui::qt::FileTailer::m_events {nullptr}
private

◆ m_lastOffset

uintmax_t ui::qt::FileTailer::m_lastOffset {0}
private

◆ m_lineBased

bool ui::qt::FileTailer::m_lineBased {true}
private

◆ m_observer

std::unique_ptr<TailObserver> ui::qt::FileTailer::m_observer
private

◆ m_parser

std::unique_ptr<parser::IDataParser> ui::qt::FileTailer::m_parser
private

◆ m_path

std::filesystem::path ui::qt::FileTailer::m_path
private

◆ m_watcher

QFileSystemWatcher ui::qt::FileTailer::m_watcher
private

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