-
Notifications
You must be signed in to change notification settings - Fork 0
/
Log.h
101 lines (79 loc) · 2.24 KB
/
Log.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
#ifndef LOG_H
#define LOG_H
#include <fstream>
#include <string>
#include <vector>
#include <stdarg.h>
/**
* @def PUSH_LOG_STACK
* @brief Pushes the logging stack with the function name that called it
*/
#define PUSH_LOG_STACK \
const StackLogger stackLoggerTempObject = StackLogger( __FUNCTION__ );
/**
* @class Log
* @brief Basic logging class
* @author Jimmy Thompson (http://jimmythompson.co.uk)
* @author wuqiong
*
* @version $Revision: 1.1 $
* @date $Date: 2012/09/08 - 14:25:00 $
*
* @details Logging class to deal with basic string messages and macro-based
* @details stack tracing. Something quick I made to handle logging in my own
* @details programs.
*/
class Log {
public:
const enum Type {
LOG_TYPE_FATAL,
LOG_TYPE_ERROR,
LOG_TYPE_WARN,
LOG_TYPE_INFO,
LOG_TYPE_DEBUG
};
static const char* TypeToString(const Type& type);
static bool Initialise(const std::string& fileName);
static bool Finalise();
static void SetThreshold(const Type& type);
static bool Fatal(const std::string& message);
static bool Fatal(const char* format, ...);
static bool Error(const std::string& message);
static bool Error(const char* format, ...);
static bool Warn(const std::string& message);
static bool Warn(const char* format, ...);
static bool Info(const std::string& message);
static bool Info(const char* format, ...);
static bool Debug(const std::string& message);
static bool Debug(const char* format, ...);
static std::string Peek();
static bool Push(const std::string& input);
static std::string Pop();
static void PrintStackTrace();
private:
Type m_threshold;
bool m_initialised;
std::string m_fileName;
std::vector<std::string> m_stack;
std::ofstream m_stream;
Log();
Log(const Log&);
~Log();
static Log& get();
void write(const char* format, ...);
bool log(const Type& type, const std::string& message);
bool log(const Type& type, const char* format, const va_list& varArgs);
Log& operator=(const Log&);
};
struct StackLogger
{
StackLogger(const std::string& input)
{
Log::Push(input);
}
~StackLogger()
{
Log::Pop();
}
};
#endif