-
Notifications
You must be signed in to change notification settings - Fork 9
/
cxlog.h
164 lines (122 loc) · 4.71 KB
/
cxlog.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#ifndef CXLOG_H
#define CXLOG_H
#include "cxglobal.h"
#include "cxinterinfo.h"
#include "cxthread.h"
class CxLogFileTactics_I
{
public:
virtual std::string log_directory() const = 0;
virtual std::string log_fileName( int type, int reason, int source, int target, int tag ) const = 0;
virtual bool log_hasFileName( int type, int reason, int source, int target, int tag ) const = 0;
};
class GM_CCXX_CORE_API CxLogManager
{
public:
static void startLog();
static void stopLog();
static void loadLogConfig();
static void setLogFileTactics(const CxLogFileTactics_I * oLogFileTactics);
static std::string fileName(int type, int reason, int source, int target, int tag);
static FILE * fileByFileName(const std::string& sFileName);
static void outLog( const std::string& sInfo, const std::string& sTitle, int type = 0, int reason = 0, int source = 0, int target = 0, int tag = 0 );
};
class GM_CCXX_CORE_API CxLogRealtime : public CxInterinfoOut_I
{
public:
CxLogRealtime();
~CxLogRealtime();
protected:
void interinfo_out( const std::string& sInfo, const std::string& sTitle, int type = 0, int reason = 0, int source = 0, int target = 0, int tag = 0 );
CxInterinfo::PlatformEnum platformValue() { return CxInterinfo::Platform_Log; }
private:
void outLogImpl( const std::string& sInfo, const std::string& sTitle, int type = 0, int reason = 0, int source = 0, int target = 0, int tag = 0 );
//*file path
std::string _filePathRt;
FILE * _fileRt;
msepoch_t _fileOpenTimeRt;
int64 _fileCountRt;
int64 _fileSizeRt;
friend class CxLogManager;
};
class GM_CCXX_CORE_API CxLogThread : public CxJoinableThread , public CxInterinfoOut_I
{
public:
CxLogThread();
~CxLogThread();
inline void stop() { _isStarted = false; join(); }
protected:
void run();
void interinfo_out( const std::string& sInfo, const std::string& sTitle, int type = 0, int reason = 0, int source = 0, int target = 0, int tag = 0 );
CxInterinfo::PlatformEnum platformValue() { return CxInterinfo::Platform_Log; }
private:
void outLogImpl( const std::string& sInfo, const std::string& sTitle, int type = 0, int reason = 0, int source = 0, int target = 0, int tag = 0 );
void doSaveLog();
private:
volatile bool _isStarted;
std::vector<std::string> * volatile _logStringsPush;
std::vector<std::string> * volatile _logStringsPop;
std::vector<std::string> _logStrings1;
std::vector<std::string> _logStrings2;
std::vector<FILE*> * volatile _logFilesPush;
std::vector<FILE*> * volatile _logFilesPop;
std::vector<FILE*> _logFiles1;
std::vector<FILE*> _logFiles2;
volatile size_t _logStringsSize;
std::string _filePathTh;
FILE * _fileTh;
msepoch_t _fileOpenTimeTh;
int64 _fileCountTh;
int64 _fileSizeTh;
friend class CxLogManager;
};
class CxLogOutStream : public CxOutStreamBase {
public:
inline ~CxLogOutStream()
{
if (!--stream->ref)
{
if ((! stream->end) && (stream->enable))
{
stream->ts << '\n';
CxLogManager::outLog(stream->ts.str(), stream->title, stream->type, stream->reason, stream->source, stream->target, stream->tag);
}
delete stream;
}
}
inline CxLogOutStream &operator=(const CxLogOutStream &other)
{
if (this != &other)
{
CxLogOutStream outStream(other);
std::swap(stream, outStream.stream);
}
return *this;
}
protected:
virtual inline CxOutStreamBase &output()
{
if (stream->end)
{
if (stream->enable)
{
CxLogManager::outLog(stream->ts.str(), stream->title, stream->type, stream->reason, stream->source, stream->target, stream->tag);
}
}
else
{
if (stream->space) stream->ts << ' ';
if (stream->lf) stream->ts << '\n';
}
return *this;
}
};
class CxLogNoOutStream : public CxNoOutStreamBase {
};
inline CxLogOutStream cxLog(CxInterinfo::LevelEnum eLevel=CxInterinfo::LevelDebug) { CxLogOutStream r; r.noend(); r.level(eLevel); return r; }
inline CxLogOutStream cxLogDebug() { CxLogOutStream r; r.noend(); r.level(CxInterinfo::LevelDebug); return r; }
inline CxLogOutStream cxLogInfo() { CxLogOutStream r; r.noend(); r.level(CxInterinfo::LevelInfo); return r; }
inline CxLogOutStream cxLogWarn() { CxLogOutStream r; r.noend(); r.level(CxInterinfo::LevelWarn); return r; }
inline CxLogOutStream cxLogError() { CxLogOutStream r; r.noend(); r.level(CxInterinfo::LevelError); return r; }
inline CxLogOutStream cxLogFatal() { CxLogOutStream r; r.noend(); r.level(CxInterinfo::LevelFatal); return r; }
#endif // CXLOG_H