-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.cpp
48 lines (30 loc) · 1.07 KB
/
log.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
#include "log.h"
#include "httprequest.h"
#include <chrono>
#include <ctime>
void Log::output(std::string output){
std::ofstream outfile;
outfile.open(filepath, std::ios_base::app);
outfile << output;
outfile.close();
}
void Log::output(std::string id, std::string output){
// void Log::output(int id, std::string output){
std::ofstream outfile;
outfile.open(filepath, std::ios_base::app);
outfile << "[ " << id << " ]: " << output;
outfile.close();
}
void Log::timestamp(std::string id){
std::time_t current = time(nullptr);
std::stringstream timestr;
timestr << "@Time: " << std::ctime(¤t);
std::cout<<std::ctime(¤t)<<std::endl;
output(id, timestr.str());
}
void Log::log_request(std::string id, HttpRequest& this_request){
std::stringstream reqstr;
reqstr << "- From: " << this_request.get_host() << ", with Port: " << this_request.get_port() << " -\n";
reqstr << "- Method: " << this_request.get_method() << ", Protocol: " << this_request.get_version() << " -\n";
output(id, reqstr.str());
}