-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogClient.cpp
107 lines (89 loc) · 1.95 KB
/
LogClient.cpp
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
/*
* LogClient.cpp
*
* Created on: Jan 14, 2015
* Author: root
*/
#include "LogClient.h"
static const char* LogLevelName[LogClient::NUM_LOG_LEVELS] =
{
"DEBUG", "INFO", "WARN", "ERROR", "FATAL"
};
LogClient::LogClient(const char* file, int line, const char* func, int logLevel)
: level_(logLevel)
{
this->log_str_ += "(";
this->log_str_ += LogLevelName[logLevel];
this->log_str_ += ")file:";
this->log_str_ += file;
this->log_str_ += " line:";
this->log_str_ += convert<std::string>(line);
this->log_str_ += " func:";
this->log_str_ += func;
this->log_str_ += " -->";
}
LogClient::~LogClient(void)
{
if (LogClient::log_func_ == NULL)
{
printf("%s\n", this->log_str_.c_str());
}
else
{
LogClient::log_func_(level_, this->log_str_.c_str(), this->log_str_.length());
}
}
LogFunc LogClient::log_func_ = 0;
void LogClient::setLogFunc(LogFunc log_func)
{
log_func_ = log_func;
}
LogFunc LogClient::logFunc(void)
{
return log_func_;
}
LogClient& LogClient::operator << (const char * cstr)
{
this->log_str_ += cstr;
return *this;
}
LogClient& LogClient::operator << (const double val)
{
this->log_str_ += convert<std::string>(val);
return *this;
}
LogClient& LogClient::operator <<(const char c)
{
this->log_str_ += convert<std::string>(c);
return *this;
}
LogClient& LogClient::operator <<(const bool val)
{
this->log_str_ += convert<std::string>(val);
return *this;
}
LogClient& LogClient::operator <<(const int &val)
{
this->log_str_ += convert<std::string>(val);
return *this;
}
LogClient& LogClient::operator <<(const long int &val)
{
this->log_str_ += convert<std::string>(val);
return *this;
}
LogClient& LogClient::operator <<(const long long int &val)
{
this->log_str_ += convert<std::string>(val);
return *this;
}
LogClient& LogClient::operator <<(const std::string &ss)
{
this->log_str_ += ss;
return *this;
}
LogClient& LogClient::operator <<(const short &val)
{
this->log_str_ += convert<std::string>(val);
return *this;
}