-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogDebug.h
168 lines (138 loc) · 4.48 KB
/
LogDebug.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
165
166
167
#ifndef BaseLib_LogDebug_h_Included
#define BaseLib_LogDebug_h_Included
#include<stdlib.h>
#include<errno.h>
#include<string.h>
#include<stdio.h>
#include<fstream>
#include<iostream>
//#include<inttypes.h>
#include<sstream>
#include "BaseLib/CommonDefines.h"
#include "BaseLib/Export.h"
namespace BaseLib
{
// ----------------------------------------------------------------
// class LogDebugBase
// ----------------------------------------------------------------
class DLL_STATE LogDebugBase
{
public:
enum LogType
{
NoLogType = -1,
INFO,
DEBUG,
WARNING,
CRITICAL,
FATAL
};
public:
LogDebugBase() {}
~LogDebugBase() {}
static void LogMessage(LogDebugBase::LogType type, const char *msg, va_list ap);
static void LogMessage(LogDebugBase::LogType type, const char *msg);
friend std::ostream& operator<<(std::ostream& ostr, const LogType& logType) throw()
{
switch(logType)
{
#define CASE(t) case t: ostr << #t; break;
CASE(INFO)
CASE(DEBUG)
CASE(WARNING)
CASE(CRITICAL)
CASE(FATAL)
#undef CASE
default:
std::cerr << TSPRETTY_FUNCTION << "CRITICAL! Missing operator<< case for LogType!" << std::endl;
break;
}
return ostr;
}
private:
static char* makeMessage(const char *fmt, va_list ap);
};
//std::ostream& operator<<(std::ostream &str, const LogDebugBase::LogType &type) throw();
// ----------------------------------------------------------------
// debug functions
// ----------------------------------------------------------------
DLL_STATE void iInfo(const char *msg, ...);
DLL_STATE void iDebug(const char *msg, ...);
DLL_STATE void iWarning(const char *msg, ...);
DLL_STATE void iCritical(const char *msg, ...);
DLL_STATE void iFatal(const char *msg, ...);
/*#define INTACT_NO_IDEBUG_MACRO while (false) iDebug
#ifdef INTACT_NO_DEBUG_OUTPUT
# define iDebug INTACT_NO_IDEBUG_MACRO
#endif
#define INTACT_NO_IWARNING_MACRO while (false) iWarning
#ifdef INTACT_NO_WARNING_OUTPUT
# define iWarning INTACT_NO_IWARNING_MACRO
#endif
*/
// ----------------------------------------------------------------
// class DebugReport
// ----------------------------------------------------------------
class DLL_STATE DebugReport
{
private:
DebugReport(std::string title = std::string(""))
: numberOfWarnings(0)
, numberOfErrors(0)
, numberOfExceptions(0)
, reportTitle(title)
{}
~DebugReport()
{}
public:
void ReportWarning(std::string report);
void ReportError(std::string report);
void ReportException(std::string report);
/*friend std::ostream& operator<<(std::ostream &ostr, const DebugReport &testReport);
{
if(testReport.GetReportTitle().empty() == false)
ostr << "-------------- " << testReport.GetReportTitle() << " DebugReport --------------" << endl;
else
ostr << "-------------- DebugReport --------------" << endl;
if(testReport.GetWarningString().empty() == false)
{
ostr << "List of Warnings: " << endl;
ostr << testReport.GetWarningString() << endl;
}
if(testReport.GetErrorString().empty() == false)
{
ostr << "List of Errors: " << endl;
ostr << testReport.GetErrorString() << endl;
}
if(testReport.GetExceptionString().empty() == false)
{
ostr << "List of Exceptions: " << endl;
ostr << testReport.GetExceptionString() << endl;
}
ostr << "Number of Warnings: " << testReport.GetNumberOfWarnings() << endl;
ostr << "Number of Errors: " << testReport.GetNumberOfErrors() << endl;
ostr << "Number of Exceptions: " << testReport.GetNumberOfExceptions() << endl;
ostr << endl;
return ostr;
}*/
std::string GetWarningString() const { return warningStream.str(); }
std::string GetErrorString() const { return errorStream.str(); }
std::string GetExceptionString() const { return exceptionStream.str(); }
std::string GetReportTitle() const { return reportTitle; }
int GetNumberOfWarnings() const { return numberOfWarnings; }
int GetNumberOfErrors() const { return numberOfErrors; }
int GetNumberOfExceptions() const { return numberOfExceptions; }
static DebugReport* GetOrCreate(); // throw();
private:
static DebugReport *staticDebugReport;
int numberOfWarnings;
int numberOfErrors;
int numberOfExceptions;
std::stringstream warningStream;
std::stringstream errorStream;
std::stringstream exceptionStream;
std::string reportTitle;
};
DLL_STATE std::ostream& operator<<(std::ostream &ostr, const DebugReport &testReport);
} // namespace BaseLib
#endif // BaseLib_LogDebug_h_IsIncluded