-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLog.h
94 lines (84 loc) · 2.32 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
/*
* Log.h
*
* Created on: Nov 14, 2015
* Author: nissassin17
*/
#ifndef LOG_H_
#define LOG_H_
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <sstream>
#define log_print(val)\
ostringstream ss;\
switch (logType){\
case WARNING:\
cerr << (val);\
break;\
case ERROR:\
cerr << (val);\
break;\
case INFO:\
cout << (val);\
break;\
case RESULT:\
cout << (val);\
break;\
case LFILE:\
ss << (val);\
(*ofile) << ss.str();\
break;\
default:\
break;\
};\
return *this;
using namespace std;
class Log {
public:
class EofObject {
public:
EofObject() {
}
};
static const Log warn;
static const Log info;
static const Log err;
static const Log result;
static const EofObject eof;
static Log file(string const& filename);
const void operator<<(EofObject const& eofObject) const;
const Log& operator<<(
basic_ostream<char>& (* const __pf)(basic_ostream<char>&)) const;
const Log& operator<<(basic_ios<char>&
(* const __pf)(basic_ios<char>&)) const;
const Log& operator<<(string const& __s) const;
const Log& operator<<(const char * const __s) const;
const Log& operator<<(ios_base& (* const __pf)(ios_base&)) const;
const Log& operator<<(const bool __n) const;
const Log& operator<<(const short __n) const;
const Log& operator<<(const unsigned short __n) const;
const Log& operator<<(const int __n) const;
const Log& operator<<(const unsigned int __n) const;
const Log& operator<<(const long __n) const;
const Log& operator<<(const unsigned long __n) const;
const Log& operator<<(const long long __n) const;
const Log& operator<<(const unsigned long long __n) const;
const Log& operator<<(const float __f) const;
const Log& operator<<(const double __f) const;
const Log& operator<<(const long double __f) const;
const Log& operator<<(const void* const __p) const;
const Log& operator<<(basic_streambuf<char> * const __sb) const;
const Log& operator<<(vector<uint8_t> const& __v) const;
private:
enum LogType {
WARNING, INFO, ERROR, RESULT, LFILE
};
Log(string const& filename); //file type
Log(LogType logType);
shared_ptr<ofstream> ofile;
LogType logType;
string filename;
};
#endif /* LOG_H_ */