LAPTOP-SNT8I5JK\Boounion
2025-09-11 71766e0946eaaf4473377a7943d6bc61da94a604
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
55
56
57
58
59
60
#pragma once
#include <functional>
 
 
#define LEVEL_DEBUG        0
#define LEVEL_INFO        1
#define LEVEL_WARN        2
#define LEVEL_ERROR        3
 
 
#define LOGD(msg, ...)        CLog::GetLog()->LogFormat(LEVEL_DEBUG, "", msg, __VA_ARGS__)
#define LOGI(msg, ...)        CLog::GetLog()->LogFormat(LEVEL_INFO, "", msg, __VA_ARGS__)
#define LOGW(msg, ...)        CLog::GetLog()->LogFormat(LEVEL_WARN, "", msg, __VA_ARGS__)
#define LOGE(msg, ...)        CLog::GetLog()->LogFormat(LEVEL_ERROR, "", msg, __VA_ARGS__)
 
 
#define OT_FILE            0x01
#define OT_ODSTRING        0x02
#define OT_TRACE        0x04
#define LOGBATHCH()                CLog::GetLog()->Batch()
#define LOGNEW()                CLog::GetLog()->BatchAndNew()
 
typedef std::function<void(int level, const char* pszMessage)> ONLOG;
 
class CLog
{
public:
    CLog();
    ~CLog();
 
public:
    void SetOnLogCallback(ONLOG funOnLog);
    static CLog *GetLog(void);
    void SetOutputTarget(int flag);
    void SetEquipmentId(const char* pszEquipmentId);
    static CString& GetCurTime(CString& strTime);
    CString& MakeFilepath(CString& strFilepath);
    CString& MakeFilepathD(CString& strFilepath, int& day);
    void LogFormat(int nLevel, const char* pszTag, char* szMessage, ...);
    void Log(int nLevel, const char* pszTag, const char* szMessage);
    void SetAutoAppendTimeString(BOOL bAutoAppendTime);
    void SetLogsDir(CString strDir);
    void Batch();
    BOOL BatchAndNew(int& nDay);
 
private:
    inline void Lock() { EnterCriticalSection(&m_criticalSection); }
    inline void Unlock() { LeaveCriticalSection(&m_criticalSection); }
 
private:
    ONLOG m_funOnLog;
    int m_nOutputTarget;
    int m_nLevel;
    BOOL m_bAutoAppendTime;
    CString m_strLogsDir;
    CString m_strEquipmentId;
    CStdioFile m_file;
    int m_nDay;                        // °´ÈÕ±£´æÒ»Ìõ¼Ç¼£¬±È½Ï´ËÊý×Ö£¬ÒÔ¾ö¶¨ÊÇ·ñ½áÅú²¢´´½¨ÐÂÎļþ
    CRITICAL_SECTION m_criticalSection;
};