| | |
| | | #define SYSTEM_LOG_MANAGER_H |
| | | |
| | | #include <string> |
| | | #include <memory> |
| | | #include <vector> |
| | | #include <mutex> |
| | | #include <chrono> |
| | | #include "Database.h" |
| | | |
| | | // 系统日志管理类 |
| | | class SystemLogManager { |
| | | public: |
| | | // 日志类型定义 |
| | | enum class LogType { |
| | | Info, |
| | | Error, |
| | |
| | | static SystemLogManager& getInstance(); |
| | | |
| | | // 设置数据库连接 |
| | | void setDatabase(std::unique_ptr<BL::Database>& db); |
| | | void setDatabase(BL::Database* db); |
| | | |
| | | // 初始化日志表 |
| | | bool initializeLogTable(); |
| | |
| | | bool log(LogType logType, const std::string& event); |
| | | bool log(LogType logType, const std::string& event, const std::string& username); |
| | | |
| | | // 获取日志 |
| | | std::vector<std::vector<std::string>> SystemLogManager::getLogs(int startPosition = -1, int count = -1); |
| | | // 获取日志内容 |
| | | std::vector<std::vector<std::string>> getLogs(int startPosition = -1, int count = -1); |
| | | |
| | | // 获取筛选后的日志数据 |
| | | std::vector<std::vector<std::string>> getFilteredLogs( |
| | |
| | | // 清理超过指定天数的旧日志 |
| | | void cleanOldLogs(int daysToKeep = 30); |
| | | |
| | | // 转换日志类型为字符串 |
| | | static std::string logTypeToString(LogType logType); |
| | | |
| | | private: |
| | | // 构造函数(私有化) |
| | | // 构造函数和析构函数 |
| | | SystemLogManager(); |
| | | ~SystemLogManager(); |
| | | |
| | | // 禁止拷贝和赋值 |
| | | SystemLogManager(const SystemLogManager&) = delete; |
| | | SystemLogManager& operator=(const SystemLogManager&) = delete; |
| | | |
| | | // 转换日志类型为字符串 |
| | | std::string logTypeToString(LogType logType) const; |
| | | |
| | | // 数据库连接 |
| | | std::unique_ptr<BL::Database>* m_pDB; |
| | | |
| | | // 单例实例 |
| | | static std::unique_ptr<SystemLogManager> m_instance; |
| | | BL::Database* m_pDB = nullptr; |
| | | |
| | | // 线程安全锁 |
| | | static std::mutex m_mutex; |