MantisBase v0.4.9
Loading...
Searching...
No Matches
mb::MbLogDatabase Class Reference

Manages SQLite database for application logs. More...

#include <log_database.h>

Public Member Functions

 MbLogDatabase (const MantisBase &app)
 Construct MbLogDatabase instance.
 ~MbLogDatabase ()
 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 (const std::string &after="", int limit=50, const std::string &level_filter="", const std::string &search_filter="", const std::string &start_date="", const std::string &end_date="")
 Get logs with cursor-based pagination and filtering (ordered by id ASC).

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 the configured retention period.

Constructor & Destructor Documentation

◆ MbLogDatabase()

mb::MbLogDatabase::MbLogDatabase ( const MantisBase & app)
explicit

Construct MbLogDatabase instance.

◆ ~MbLogDatabase()

mb::MbLogDatabase::~MbLogDatabase ( )

Destructor - stops cleanup thread and closes database.

Member Function Documentation

◆ getLogs()

json mb::MbLogDatabase::getLogs ( const std::string & after = "",
int limit = 50,
const std::string & level_filter = "",
const std::string & search_filter = "",
const std::string & start_date = "",
const std::string & end_date = "" )

Get logs with cursor-based pagination and filtering (ordered by id ASC).

Parameters
afterCursor ID to fetch records after (empty = start from beginning)
limitMaximum number of records to return (default 50, max 1000)
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)
Returns
JSON object with logs, cursor, and has_more

◆ init()

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

Initialize database: create table and start cleanup thread.

Returns
true if initialization successful, false otherwise

◆ insertLog()

bool mb::MbLogDatabase::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, MbAuth, MbDatabase, MbEntity, MbEntitySchema, etc.)
messageShort message (e.g., "MbAuth Failed", "MbDatabase 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:
  • /home/runner/work/mantisbase/mantisbase/include/mantisbase/core/logger/log_database.h
  • /home/runner/work/mantisbase/mantisbase/src/core/logger/log_database.cpp