C++客户端开发接口库 V5.1.8.15
连接信创集成中间件服务程序的二次开发接口
载入中...
搜索中...
未找到
MDWLogger.h
1#pragma once
2#include <string>
3#include <fstream>
4#include <vector>
5#include <list>
6#include <chrono>
7#include <thread>
8#include <mutex>
9#include <ctime>
10#include <atomic>
11#include <condition_variable>
12
13namespace mdwc
14{
17 {
19 llError = 0,
23 llNormal = 2,
25 llDebug = 3
26 };
27
29 struct MDWLogMsg
30 {
32 std::chrono::system_clock::time_point dtTime;
36 std::string sFunctionName;
38 std::string sLogMessage;
39 };
40
42 class CMDWLogger
43 {
44 private:
46 std::string m_sProductName;
48 std::fstream m_fsLogFileObj;
50 std::string m_sLogFileName;
52 std::tm m_LogFileDate;
54 std::string m_sExecPath;
56 std::unique_ptr<std::thread> m_thrProcLog;
58 std::mutex m_queueMutex;
60 std::mutex m_fileMutex;
62 std::condition_variable m_cvHavelLogMsg;
64 std::atomic<bool> m_bStopThread;
66 bool m_bWriteDebugLog;
68 std::vector<int> m_WriteDataLogFuns;
70 int64_t m_iLastWriteFileTime;
72 std::chrono::system_clock::time_point m_tLastLogTime;
74 int m_iLogFileRetentionDays;
76 std::list<MDWLogMsg> m_LogMsgQuenue;
77 private:
78 // 禁止拷贝构造函数
79 CMDWLogger(const CMDWLogger&) = delete;
80 // 禁止拷贝赋值运算符
81 CMDWLogger& operator=(const CMDWLogger&) = delete;
82
84 void ClearFloderLogFile();
86 void ProcessLogMsg();
88 void CreatModalLogFile();
89 public:
97 CMDWLogger(const std::string& sProductName, const std::string& sWorkDirectory = "", int iLogFileRetentionDays = 100);
98 ~CMDWLogger();
99 public:
101 void SetWriteDebugLog(bool bWrite) { m_bWriteDebugLog = bWrite; };
107 void SetDebugLogFuntion(const std::string& sFunConfig);
114 bool NeedWriteDebugLog(int iFunNo);
116 void CloseLogFile();
118 void OpenLogFile();
120 void ClearLogFile();
122 void StartProcLog();
124 void StopProcLog();
125
126 public:
133 void Push(LOGLEVEL Level, const std::string& sFunctionName, const std::list<std::string>& lstMsg);
134
141 void Push(LOGLEVEL Level, const std::string& sFunctionName, const std::string& sLogMsg);
142
149 void Push(LOGLEVEL Level, const std::string& sFunctionName, const char* fmt, ...);
150
156 void PushError(const std::string& sFunctionName, const std::string& sLogMsg);
162 void PushError(const std::string& sFunctionName, const char* fmt, ...);
163
169 void PushWaring(const std::string& sFunctionName, const std::string& sLogMsg);
170
176 void PushWaring(const std::string& sFunctionName, const char* fmt, ...);
177
183 void Push(const std::string& sFunctionName, const std::exception& ex);
184
190 bool Pop(MDWLogMsg& logmsg);
191
196 bool WriteFinshed();
197 };
198}
bool Pop(MDWLogMsg &logmsg)
定义 MDWLogger.cpp:457
void ClearLogFile()
定义 MDWLogger.cpp:206
bool NeedWriteDebugLog(int iFunNo)
定义 MDWLogger.cpp:151
void PushError(const std::string &sFunctionName, const std::string &sLogMsg)
定义 MDWLogger.cpp:382
void PushWaring(const std::string &sFunctionName, const std::string &sLogMsg)
定义 MDWLogger.cpp:412
void SetWriteDebugLog(bool bWrite)
定义 MDWLogger.h:101
void StopProcLog()
定义 MDWLogger.cpp:230
void StartProcLog()
定义 MDWLogger.cpp:224
void CloseLogFile()
定义 MDWLogger.cpp:186
void OpenLogFile()
定义 MDWLogger.cpp:193
bool WriteFinshed()
定义 MDWLogger.cpp:468
void Push(LOGLEVEL Level, const std::string &sFunctionName, const std::list< std::string > &lstMsg)
定义 MDWLogger.cpp:344
void SetDebugLogFuntion(const std::string &sFunConfig)
定义 MDWLogger.cpp:115
定义 AutoUpdateHelper.h:8
LOGLEVEL
定义 LogQueue.h:11
@ llNormal
定义 LogQueue.h:17
@ llDebug
定义 LogQueue.h:19
@ llWaring
定义 MDWLogger.h:21
@ llError
定义 LogQueue.h:13
定义 LogQueue.h:24
std::string sFunctionName
定义 LogQueue.h:30
std::string sLogMessage
定义 LogQueue.h:32
LOGLEVEL Level
定义 LogQueue.h:28
std::chrono::system_clock::time_point dtTime
定义 LogQueue.h:26