-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLog.cpp
More file actions
111 lines (103 loc) · 2.5 KB
/
Log.cpp
File metadata and controls
111 lines (103 loc) · 2.5 KB
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
/*
* Log.cpp
*
* Created on: Nov 14, 2015
* Author: nissassin17
*/
#include "Log.h"
Log::Log(LogType logType) :
logType(logType) {
}
const Log& Log::operator<<(
basic_ostream<char>& (* const __pf)(basic_ostream<char>&)) const {
log_print(__pf);
}
const Log& Log::operator<<(basic_ios<char>&
(* const __pf)(basic_ios<char>&)) const {
log_print(__pf);
}
const Log& Log::operator<<(ios_base& (* const __pf)(ios_base&)) const {
log_print(__pf);
}
const Log& Log::operator<<(string const& __s) const {
log_print(__s);
}
const Log& Log::operator<<(const bool __n) const {
log_print(__n);
}
const Log& Log::operator<<(const short __n) const {
log_print(__n);
}
const Log& Log::operator<<(const unsigned short __n) const {
log_print(__n);
}
const Log& Log::operator<<(const int __n) const {
log_print(__n);
}
const Log& Log::operator<<(const unsigned int __n) const {
log_print(__n);
}
const Log& Log::operator<<(const long __n) const {
log_print(__n);
}
const Log& Log::operator<<(const unsigned long __n) const {
log_print(__n);
}
const Log& Log::operator<<(const long long __n) const {
log_print(__n);
}
const Log& Log::operator<<(const unsigned long long __n) const {
log_print(__n);
}
const Log& Log::operator<<(const float __f) const {
log_print(__f);
}
const Log& Log::operator<<(const double __f) const {
log_print(__f);
}
const Log& Log::operator<<(const long double __f) const {
log_print(__f);
}
const Log& Log::operator<<(const void* const __p) const {
log_print(__p);
}
const Log& Log::operator<<(basic_streambuf<char>* const __sb) const {
log_print(__sb);
}
const Log& Log::operator<<(const char * const __s) const {
log_print(__s);
}
const void Log::operator<<(EofObject const& eofObject) const {
ofile->close();
}
const Log& Log::operator<<(vector<uint8_t> const& __v) const {
if (this->logType == LFILE) {
for (int i = 0; i < __v.size(); i++)
(*ofile) << __v[i];
return *this;
}
string str;
for (int i = 0; i < __v.size(); i++) {
if (i and i % 16 == 0)
str += "\n";
else if (i and i % 8 == 0)
str += " | ";
char a[3];
sprintf(a, "%02x", (uint8_t) __v[i]);
str += " ";
str += a;
}
return (*this) << str;
}
const Log Log::warn(WARNING);
const Log Log::err(ERROR);
const Log Log::info(INFO);
const Log Log::result(RESULT);
const Log::EofObject Log::eof = Log::EofObject();
Log Log::file(string const& filename) {
return Log(filename);
}
Log::Log(string const& filename) :
logType(LFILE), filename(filename), ofile(
new ofstream(filename, ios::out bitor ios::binary)) {
}