Persist and query application and project logs across session SQLite files. Project logs use their working folder's logs directory. Pages span the application and currently open projects.
More...
#include <log_store.hpp>
|
| struct | Database |
| | Own an SQLite connection and close it on destruction. More...
|
| struct | Folder |
| | Associate a log folder with its live session database. More...
|
|
| void | setApplicationFolder (const std::filesystem::path &folder) |
| | Set the destination folder for application and fallback entries. Locks _mutex and closes the current application session when no other owner remains.
|
| void | beginOpening (const std::string &openingTag) |
| | Starts a new opening tag, clearing any previous resolution of the same tag.
|
| void | openProject (const std::string &id, const std::filesystem::path &workingFolder, const std::string &openingTag=std::string()) |
| | Open a new project log session and flush buffered opening lines. Creates <workingFolder>/logs and a session file. Falls back to the application log if creation fails.
|
| void | discardOpening (const std::string &openingTag) |
| | Move a failed project opening's buffered lines into the application log. Clears the project tag and discards buffered lines even if the application session cannot be opened.
|
| bool | suspendProject (const std::string &id) |
| | Close a project's live session before its folder is renamed.
|
| bool | moveProject (const std::string &id, const std::filesystem::path &workingFolder) |
| | Reopen a project session after its working folder moves. Closes the old-path connection and reopens the moved file so SQLite can clean up WAL files.
|
| bool | closeProject (const std::string &id) |
| | Forget a project folder and release its session connection. Waits for in-flight operations on this connection before releasing it.
|
| std::optional< Entry > | prepare (Entry entry) |
| | Identify and stamp an entry without accessing SQLite. UID generation failures and invalid supplied UIDs are reported directly to stderr and the entry is dropped.
|
| void | persist (const Entry &original) |
| | Persist an already stamped entry in its project, opening buffer, or application session. Database insert errors are printed directly to stderr.
|
| void | persistApplication (const Entry &original) |
| | Persist an entry only in the application session while retaining its project identity.
|
| std::optional< Entry > | write (Entry entry) |
| | Identify, stamp, and persist an entry synchronously.
|
| Page | page (const Query &query) |
| | Query the newest matching entries across the application and open projects. Takes a snapshot of registered folders; inaccessible files and SQLite query errors are skipped.
|
|
| static bool | isOpeningTag (const std::string &project) |
| | Check whether a project identifier is an opening tag.
|
|
| std::uint64_t | nextStamp (std::uint64_t observedUs=0) |
| | Allocates a timestamp without waiting for SQLite or project operations.
|
| void | selectFolder (const Folder &folder, const Query &query, std::size_t count, std::vector< Entry > &out) |
| | Append matching entries from session files in a folder. Uses the live connection for its current file and opens closed sessions read-only and immutable.
|
|
| static std::uint64_t | nowUs () |
| | Read the system clock in Unix-epoch microseconds.
|
| static std::shared_ptr< Database > | openFile (const std::filesystem::path &file) |
| | Open or create an SQLite log database and ensure its schema exists. Configures WAL and normal synchronization; SQLite setup failures other than opening or schema creation are ignored.
|
| static bool | hasConsoleVisibility (sqlite3 *db, bool &present) |
| | Detects whether a session has the Console visibility column.
|
| static std::shared_ptr< Database > | create (const std::filesystem::path &folder, std::uint64_t stamp) |
| | Create a session database in a log folder.
|
| static void | insert (Database &database, const Entry &entry) |
| | Insert an entry into an open session database. SQLite prepare or write failures are reported directly to stderr to avoid log recursion.
|
| static std::string | escape (const std::string &text) |
| | Escape SQLite LIKE wildcard and escape characters.
|
| static void | select (sqlite3 *db, const Query &query, std::size_t count, std::vector< Entry > &out) |
| | Append the newest matching rows from one database, newest first. SQL preparation or stepping failures are reported directly to stderr.
|
|
| std::mutex | _mutex |
| | Protects folder registrations, opening buffers, and session references.
|
| std::filesystem::path | _appFolder |
| | Application log session directory.
|
| std::map< std::string, Folder > | _projects |
| | Currently open project folders indexed by project id.
|
| std::map< std::string, std::vector< Entry > > | _opening |
| | Lines buffered before a project opens, keyed by opening tag.
|
| std::map< std::string, std::string > | _resolvedOpening |
| | Resolved opening tags; an empty ID sends late entries to the application log.
|
| std::shared_ptr< Database > | _app |
| | Shared owner of the current application session connection.
|
| std::atomic< std::uint64_t > | _last {0} |
| | Last allocated arrival timestamp or session stamp.
|
Persist and query application and project logs across session SQLite files. Project logs use their working folder's logs directory. Pages span the application and currently open projects.
Definition at line 131 of file log_store.hpp.
◆ beginOpening()
| void fray::logs::LogStore::beginOpening |
( |
const std::string & | openingTag | ) |
|
|
inline |
Starts a new opening tag, clearing any previous resolution of the same tag.
- Parameters
-
| openingTag | Temporary identifier for the opening project. |
Definition at line 566 of file log_store.hpp.
◆ closeProject()
| bool fray::logs::LogStore::closeProject |
( |
const std::string & | id | ) |
|
|
inline |
Forget a project folder and release its session connection. Waits for in-flight operations on this connection before releasing it.
- Parameters
-
| id | Project identifier to close. |
- Returns
- True if the connection was closed or the project was absent.
Definition at line 704 of file log_store.hpp.
◆ create()
| std::shared_ptr< Database > fray::logs::LogStore::create |
( |
const std::filesystem::path & | folder, |
|
|
std::uint64_t | stamp ) |
|
inlinestaticprivate |
Create a session database in a log folder.
- Parameters
-
| folder | Directory to create if necessary. |
| stamp | Timestamp incorporated in the session filename. |
- Returns
- Shared database owner on success; null if directory creation or database opening fails.
Definition at line 314 of file log_store.hpp.
◆ discardOpening()
| void fray::logs::LogStore::discardOpening |
( |
const std::string & | openingTag | ) |
|
|
inline |
Move a failed project opening's buffered lines into the application log. Clears the project tag and discards buffered lines even if the application session cannot be opened.
- Parameters
-
| openingTag | Tag identifying the buffered lines. |
Definition at line 619 of file log_store.hpp.
◆ escape()
| std::string fray::logs::LogStore::escape |
( |
const std::string & | text | ) |
|
|
inlinestaticprivate |
Escape SQLite LIKE wildcard and escape characters.
- Parameters
-
| text | Literal substring to escape. |
- Returns
- Escaped LIKE pattern fragment.
Definition at line 372 of file log_store.hpp.
◆ hasConsoleVisibility()
| bool fray::logs::LogStore::hasConsoleVisibility |
( |
sqlite3 * | db, |
|
|
bool & | present ) |
|
inlinestaticprivate |
Detects whether a session has the Console visibility column.
- Parameters
-
| db | Session database, including legacy read-only sessions. |
| present | Receives whether the column exists. |
- Returns
- True when the schema was inspected successfully.
Definition at line 288 of file log_store.hpp.
◆ insert()
| void fray::logs::LogStore::insert |
( |
Database & | database, |
|
|
const Entry & | entry ) |
|
inlinestaticprivate |
Insert an entry into an open session database. SQLite prepare or write failures are reported directly to stderr to avoid log recursion.
- Parameters
-
| database | Open database receiving the entry. |
| entry | Stamped entry to insert. |
Definition at line 331 of file log_store.hpp.
◆ isOpeningTag()
| bool fray::logs::LogStore::isOpeningTag |
( |
const std::string & | project | ) |
|
|
inlinestatic |
Check whether a project identifier is an opening tag.
- Parameters
-
| project | Project identifier or opening tag. |
- Returns
- True if it starts with "opening:"; false otherwise.
Definition at line 556 of file log_store.hpp.
◆ moveProject()
| bool fray::logs::LogStore::moveProject |
( |
const std::string & | id, |
|
|
const std::filesystem::path & | workingFolder ) |
|
inline |
Reopen a project session after its working folder moves. Closes the old-path connection and reopens the moved file so SQLite can clean up WAL files.
- Parameters
-
| id | Open project identifier. |
| workingFolder | New project working directory. |
- Returns
- True when the session was reopened or no session exists.
Definition at line 666 of file log_store.hpp.
◆ nextStamp()
| std::uint64_t fray::logs::LogStore::nextStamp |
( |
std::uint64_t | observedUs = 0 | ) |
|
|
inlineprivate |
Allocates a timestamp without waiting for SQLite or project operations.
- Parameters
-
| observedUs | Captured arrival time, or zero to use the current time. |
- Returns
- A timestamp at least observedUs and greater than every previous stamp in this store.
Definition at line 233 of file log_store.hpp.
◆ nowUs()
| std::uint64_t fray::logs::LogStore::nowUs |
( |
| ) |
|
|
inlinestaticprivate |
Read the system clock in Unix-epoch microseconds.
- Returns
- Current clock value in microseconds.
Definition at line 221 of file log_store.hpp.
◆ openFile()
| std::shared_ptr< Database > fray::logs::LogStore::openFile |
( |
const std::filesystem::path & | file | ) |
|
|
inlinestaticprivate |
Open or create an SQLite log database and ensure its schema exists. Configures WAL and normal synchronization; SQLite setup failures other than opening or schema creation are ignored.
- Parameters
-
- Returns
- Shared database owner on success; null on open or schema failure.
Definition at line 252 of file log_store.hpp.
◆ openProject()
| void fray::logs::LogStore::openProject |
( |
const std::string & | id, |
|
|
const std::filesystem::path & | workingFolder, |
|
|
const std::string & | openingTag = std::string() ) |
|
inline |
Open a new project log session and flush buffered opening lines. Creates <workingFolder>/logs and a session file. Falls back to the application log if creation fails.
- Parameters
-
| id | Project identifier assigned to buffered entries. |
| workingFolder | Project working directory. |
| openingTag | Tag whose buffered lines should be transferred, if present. |
Definition at line 580 of file log_store.hpp.
◆ page()
| Page fray::logs::LogStore::page |
( |
const Query & | query | ) |
|
|
inline |
Query the newest matching entries across the application and open projects. Takes a snapshot of registered folders; inaccessible files and SQLite query errors are skipped.
- Parameters
-
| query | Cursor, limit, and filters for the page. |
- Returns
- Matching entries oldest first and an exhaustion flag; at least one entry is requested.
Definition at line 846 of file log_store.hpp.
◆ persist()
| void fray::logs::LogStore::persist |
( |
const Entry & | original | ) |
|
|
inline |
Persist an already stamped entry in its project, opening buffer, or application session. Database insert errors are printed directly to stderr.
- Parameters
-
| original | Entry returned by prepare. |
Definition at line 765 of file log_store.hpp.
◆ persistApplication()
| void fray::logs::LogStore::persistApplication |
( |
const Entry & | original | ) |
|
|
inline |
Persist an entry only in the application session while retaining its project identity.
- Parameters
-
| original | Prepared entry to persist. |
Definition at line 803 of file log_store.hpp.
◆ prepare()
| std::optional< Entry > fray::logs::LogStore::prepare |
( |
Entry | entry | ) |
|
|
inline |
Identify and stamp an entry without accessing SQLite. UID generation failures and invalid supplied UIDs are reported directly to stderr and the entry is dropped.
- Parameters
-
| entry | Entry to stamp and route; arrivedUs may contain a captured arrival time, and an empty UID is assigned. |
- Returns
- Stamped entry, or nullopt if the UID is invalid or could not be assigned.
Definition at line 731 of file log_store.hpp.
◆ select()
| void fray::logs::LogStore::select |
( |
sqlite3 * | db, |
|
|
const Query & | query, |
|
|
std::size_t | count, |
|
|
std::vector< Entry > & | out ) |
|
inlinestaticprivate |
Append the newest matching rows from one database, newest first. SQL preparation or stepping failures are reported directly to stderr.
- Parameters
-
| db | Open SQLite database to query. |
| query | Cursor and filters to apply. |
| count | Maximum number of rows to append. |
| out | Destination vector; existing entries are retained. |
Definition at line 393 of file log_store.hpp.
◆ selectFolder()
| void fray::logs::LogStore::selectFolder |
( |
const Folder & | folder, |
|
|
const Query & | query, |
|
|
std::size_t | count, |
|
|
std::vector< Entry > & | out ) |
|
inlineprivate |
Append matching entries from session files in a folder. Uses the live connection for its current file and opens closed sessions read-only and immutable.
- Parameters
-
| folder | Folder and optional live session to scan. |
| query | Cursor and filters to apply. |
| count | Maximum rows to select from each session. |
| out | Destination vector; existing entries are retained. |
Definition at line 481 of file log_store.hpp.
◆ setApplicationFolder()
| void fray::logs::LogStore::setApplicationFolder |
( |
const std::filesystem::path & | folder | ) |
|
|
inline |
Set the destination folder for application and fallback entries. Locks _mutex and closes the current application session when no other owner remains.
- Parameters
-
| folder | Directory for application session files. |
Definition at line 543 of file log_store.hpp.
◆ suspendProject()
| bool fray::logs::LogStore::suspendProject |
( |
const std::string & | id | ) |
|
|
inline |
Close a project's live session before its folder is renamed.
- Parameters
-
| id | Open project identifier. |
- Returns
- True if the connection is closed or no session exists.
Definition at line 646 of file log_store.hpp.
◆ write()
| std::optional< Entry > fray::logs::LogStore::write |
( |
Entry | entry | ) |
|
|
inline |
Identify, stamp, and persist an entry synchronously.
- Parameters
-
| entry | Entry with an optional captured arrival time and missing UID to assign. |
- Returns
- Prepared entry even if persistence fails, or nullopt if its UID is invalid or unavailable.
Definition at line 831 of file log_store.hpp.
◆ _app
| std::shared_ptr<Database> fray::logs::LogStore::_app |
|
private |
Shared owner of the current application session connection.
Definition at line 211 of file log_store.hpp.
◆ _appFolder
| std::filesystem::path fray::logs::LogStore::_appFolder |
|
private |
Application log session directory.
Definition at line 195 of file log_store.hpp.
◆ _last
| std::atomic<std::uint64_t> fray::logs::LogStore::_last {0} |
|
private |
Last allocated arrival timestamp or session stamp.
Definition at line 215 of file log_store.hpp.
◆ _mutex
| std::mutex fray::logs::LogStore::_mutex |
|
private |
Protects folder registrations, opening buffers, and session references.
Definition at line 191 of file log_store.hpp.
◆ _opening
| std::map<std::string, std::vector<Entry> > fray::logs::LogStore::_opening |
|
private |
Lines buffered before a project opens, keyed by opening tag.
Definition at line 203 of file log_store.hpp.
◆ _projects
| std::map<std::string, Folder> fray::logs::LogStore::_projects |
|
private |
Currently open project folders indexed by project id.
Definition at line 199 of file log_store.hpp.
◆ _resolvedOpening
| std::map<std::string, std::string> fray::logs::LogStore::_resolvedOpening |
|
private |
Resolved opening tags; an empty ID sends late entries to the application log.
Definition at line 207 of file log_store.hpp.
The documentation for this class was generated from the following file: