LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
Loading...
Searching...
No Matches
FileTailer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "EventsContainer.hpp"
4#include "IDataParser.hpp"
5
6#include <QFileSystemWatcher>
7#include <QObject>
8#include <QString>
9
10#include <cstdint>
11#include <filesystem>
12#include <memory>
13
14namespace ui::qt
15{
16
32class FileTailer : public QObject
33{
34 Q_OBJECT
35
36public:
37 explicit FileTailer(QObject* parent = nullptr);
38 ~FileTailer() override = default;
39
42 void Start(const std::filesystem::path& path,
43 std::unique_ptr<parser::IDataParser> parser,
44 db::EventsContainer& events);
45
46 void Stop();
47 bool IsActive() const { return m_active; }
48
49 const std::filesystem::path& FilePath() const { return m_path; }
50
51signals:
53 void NewEventsAvailable(std::size_t count);
54
56 void TailingError(const QString& message);
57
58private slots:
59 void OnFileChanged(const QString& path);
60
61private:
63 {
65 std::size_t added {0};
66
68
69 void ProgressUpdated() override {}
70 void NewEventFound(db::LogEvent&& ev) override
71 {
72 container.AddEvent(std::move(ev));
73 ++added;
74 }
76 std::vector<std::pair<int, db::LogEvent::EventItems>>&& batch) override
77 {
78 for (auto& [id, items] : batch)
79 {
80 container.AddEvent(db::LogEvent(id, std::move(items)));
81 ++added;
82 }
83 }
84 };
85
86 QFileSystemWatcher m_watcher;
87 std::unique_ptr<parser::IDataParser> m_parser;
88 std::unique_ptr<TailObserver> m_observer;
90 std::filesystem::path m_path;
91 uintmax_t m_lastOffset {0};
92 bool m_active {false};
93 bool m_lineBased {true};
94};
95
96} // namespace ui::qt
Container class for managing collections of LogEvent objects.
Interface definitions for data parsing components.
High-performance, thread-safe container for managing large collections of LogEvent objects.
Definition EventsContainer.hpp:129
void AddEvent(LogEvent &&event)
Adds a new event to the container.
Definition EventsContainer.cpp:28
Represents a single, structured log event with key-value data.
Definition LogEvent.hpp:97
Observer interface for receiving notifications from data parsers.
Definition IDataParser.hpp:52
Definition FileTailer.hpp:33
const std::filesystem::path & FilePath() const
Definition FileTailer.hpp:49
void Start(const std::filesystem::path &path, std::unique_ptr< parser::IDataParser > parser, db::EventsContainer &events)
Definition FileTailer.cpp:30
uintmax_t m_lastOffset
Definition FileTailer.hpp:91
bool m_lineBased
Definition FileTailer.hpp:93
std::unique_ptr< parser::IDataParser > m_parser
Definition FileTailer.hpp:87
db::EventsContainer * m_events
Definition FileTailer.hpp:89
QFileSystemWatcher m_watcher
Definition FileTailer.hpp:86
~FileTailer() override=default
void Stop()
Definition FileTailer.cpp:77
void NewEventsAvailable(std::size_t count)
Emitted on the main thread after new events have been added.
void OnFileChanged(const QString &path)
Definition FileTailer.cpp:99
std::filesystem::path m_path
Definition FileTailer.hpp:90
bool m_active
Definition FileTailer.hpp:92
bool IsActive() const
Definition FileTailer.hpp:47
std::unique_ptr< TailObserver > m_observer
Definition FileTailer.hpp:88
void TailingError(const QString &message)
Emitted when a tailing read or parse error occurs.
Data parsing components and interfaces.
Definition IControler.hpp:22
Definition ConfigEditorDialog.cpp:19
Definition FileTailer.hpp:63
void ProgressUpdated() override
Called when parsing progress is updated.
Definition FileTailer.hpp:69
void NewEventFound(db::LogEvent &&ev) override
Called when a new event is discovered during parsing.
Definition FileTailer.hpp:70
TailObserver(db::EventsContainer &c)
Definition FileTailer.hpp:67
std::size_t added
Definition FileTailer.hpp:65
db::EventsContainer & container
Definition FileTailer.hpp:64
void NewEventBatchFound(std::vector< std::pair< int, db::LogEvent::EventItems > > &&batch) override
Called when a batch of new events is discovered during parsing.
Definition FileTailer.hpp:75