MantisBase v0.3.4
Loading...
Searching...
No Matches
mb::LogDatabase Class Reference

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ LogDatabase()

mb::LogDatabase::LogDatabase ( )

Construct LogDatabase instance.

◆ ~LogDatabase()

mb::LogDatabase::~LogDatabase ( )

Destructor - stops cleanup thread and closes database.

Member Function Documentation

◆ getLogs()

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.

Parameters
pagePage number (1-based)
page_sizeNumber of records per page
level_filterOptional level filter (empty = all levels)
search_filterOptional message search filter (empty = no filter)
start_dateOptional start date filter (ISO 8601 format, empty = no filter)
end_dateOptional end date filter (ISO 8601 format, empty = no filter)
sort_bySort field (default: "timestamp")
sort_orderSort order ("asc" or "desc", default: "desc")
Returns
JSON object with logs and pagination info

◆ init()

bool mb::LogDatabase::init ( const std::string &  data_dir = "")

Initialize database: create table and start cleanup thread.

Returns
true if initialization successful, false otherwise

◆ insertLog()

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.

Parameters
levelLog level (trace, debug, info, warn, critical)
originComponent/system origin (System, Auth, Database, Entity, EntitySchema, etc.)
messageShort message (e.g., "Auth Failed", "Database Connected")
detailsLong description of the message
dataOptional JSON data associated with the log
Returns
true if insert successful, false otherwise

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