|
MantisBase v0.3.4
|
Manages SQLite database for application logs. More...
#include <log_database.h>
Public Member Functions | |
| LogDatabase () | |
| Construct LogDatabase instance. | |
| ~LogDatabase () | |
| Destructor - stops cleanup thread and closes database. | |
| bool | init (const std::string &data_dir="") |
| Initialize database: create table and start cleanup thread. | |
| bool | insertLog (const std::string &level, const std::string &origin, const std::string &message, const std::string &details, const json &data=json::object()) |
| Insert a log entry into the database. | |
| json | getLogs (int page=1, int page_size=50, const std::string &level_filter="", const std::string &search_filter="", const std::string &start_date="", const std::string &end_date="", const std::string &sort_by="timestamp", const std::string &sort_order="desc") |
| Get logs with pagination, filtering, and sorting. | |
Manages SQLite database for application logs.
Provides methods to store logs in a separate SQLite database, with automatic cleanup of logs older than 5 days.
| mb::LogDatabase::LogDatabase | ( | ) |
Construct LogDatabase instance.
| mb::LogDatabase::~LogDatabase | ( | ) |
Destructor - stops cleanup thread and closes database.
| json mb::LogDatabase::getLogs | ( | int | page = 1, |
| int | page_size = 50, |
||
| const std::string & | level_filter = "", |
||
| const std::string & | search_filter = "", |
||
| const std::string & | start_date = "", |
||
| const std::string & | end_date = "", |
||
| const std::string & | sort_by = "timestamp", |
||
| const std::string & | sort_order = "desc" |
||
| ) |
Get logs with pagination, filtering, and sorting.
| page | Page number (1-based) |
| page_size | Number of records per page |
| level_filter | Optional level filter (empty = all levels) |
| search_filter | Optional message search filter (empty = no filter) |
| start_date | Optional start date filter (ISO 8601 format, empty = no filter) |
| end_date | Optional end date filter (ISO 8601 format, empty = no filter) |
| sort_by | Sort field (default: "timestamp") |
| sort_order | Sort order ("asc" or "desc", default: "desc") |
| bool mb::LogDatabase::init | ( | const std::string & | data_dir = "" | ) |
Initialize database: create table and start cleanup thread.
| bool mb::LogDatabase::insertLog | ( | const std::string & | level, |
| const std::string & | origin, | ||
| const std::string & | message, | ||
| const std::string & | details, | ||
| const json & | data = json::object() |
||
| ) |
Insert a log entry into the database.
| level | Log level (trace, debug, info, warn, critical) |
| origin | Component/system origin (System, Auth, Database, Entity, EntitySchema, etc.) |
| message | Short message (e.g., "Auth Failed", "Database Connected") |
| details | Long description of the message |
| data | Optional JSON data associated with the log |