forked from jimmythompson/log
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLog.h
91 lines (73 loc) · 1.94 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
#ifndef LOG_H
#define LOG_H
#include <fstream>
#include <string>
#include <vector>
/**
* @def PUSH_LOG_STACK
* @brief Pushes the logging stack with the function name that called it
*/
#define PUSH_LOG_STACK \
Log::push( __FUNCTION__ );
/**
* @def POP_LOG_STACK
* @brief Pops the logging stack
*/
#define POP_LOG_STACK \
Log::pop();
/**
* @class Log
* @brief Basic logging class
* @author Jimmy Thompson
*
* @version $Revision: 1.0 $
* @date $Date: 2012/09/08 - 14:25:00 $
*
* @details Logging class to deal with basic string messages and
* @details macro-based stack tracing. Something quick I made to
* @details handle logging in my own programs; made to be basic.
*/
class Log {
public:
static const enum Type {
FATAL,
ERROR,
WARN,
INFO,
DEBUG
};
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 std::string& message );
void write( const char* message );
bool log( const Type type, const std::string& message );
Log& operator=(const Log&);
public:
static const char* typeToString(Type type);
static bool initialise( const std::string& fileName );
static bool initialise( const char* fileName );
static bool fatal( const std::string& message );
static bool fatal( const char* message );
static bool error( const std::string& message );
static bool error( const char* message );
static bool warn( const std::string& message );
static bool warn( const char* message );
static bool info( const std::string& message );
static bool info( const char* message );
static bool debug( const std::string& message );
static bool debug( const char* message );
//Prefix to string
static std::string peek();
static bool push(const std::string& input);
static bool push(const char* input);
static std::string pop();
};
#endif