-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.cpp
More file actions
58 lines (54 loc) · 1.14 KB
/
Logger.cpp
File metadata and controls
58 lines (54 loc) · 1.14 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
#include "Logger.hpp"
#include "Config.hpp"
#include "Request.hpp"
#include "Response.hpp"
Logger::Logger(LogType type, ostream &os) : minLogType(type), os(&os)
{
}
void Logger::log(LogType type, const string &message)
{
if (type < minLogType)
return;
*os << typeToStr(type);
*os << " : " << message << endl;
}
void Logger::log(LogType type, const Config &conf)
{
if (type < minLogType)
return;
*os << typeToStr(type) << ": ";
*os << conf;
}
void Logger::log(LogType type, const Request &req)
{
if (type < minLogType)
return;
*os << typeToStr(type) << ": ";
*os << req;
}
void Logger::log(LogType type, const Response &resp)
{
if (type < minLogType)
return;
*os << typeToStr(type) << ": ";
*os << resp;
}
void Logger::setOut(ostream &os)
{
this->os = &os;
}
const string &Logger::typeToStr(LogType type)
{
string strType;
switch (type)
{
case LogType::ERROR:
return strType = "ERROR";
case LogType::DEBUG:
return strType = "DEBUG";
case LogType::FATAL:
return strType = "FATAL";
default:
return strType = "UNKNOWN";
}
}