LAPTOP-T815PCOQ\25526
2024-11-20 8dbd14952aa622587a92866dc01943869ea4f9dc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef SYSTEM_LOG_MANAGER_H
#define SYSTEM_LOG_MANAGER_H
 
#include <string>
#include <memory>
#include <mutex>
#include <chrono>
#include "Database.h"
 
class SystemLogManager {
public:
    enum class LogType {
        Info,     // ÐÅÏ¢ÈÕÖ¾
        Error,    // ´íÎóÈÕÖ¾
        Operation // ²Ù×÷ÈÕÖ¾
    };
 
    // »ñÈ¡µ¥ÀýʵÀý
    static SystemLogManager& getInstance();
 
    // ÉèÖÃÊý¾Ý¿âÁ¬½Ó
    void setDatabase(std::unique_ptr<BL::Database>& db);
 
    // Ìí¼ÓÈÕÖ¾
    bool log(LogType logType, const std::string& event, const std::string& username = "SYSTEM");
 
    // »ñÈ¡ÈÕÖ¾
    std::vector<std::vector<std::string>> SystemLogManager::getLogs(int startPosition = -1, int count = -1);
 
    // ³õʼ»¯ÈÕÖ¾±í
    bool initializeLogTable();
 
private:
    // ¹¹Ô캯Êý£¨Ë½Óл¯£©
    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;
 
    // Ḭ̈߳²È«Ëø
    static std::mutex m_mutex;
};
 
#endif // SYSTEM_LOG_MANAGER_H