Wrote the print_logs funciton for debugging and changed the location of the test .log files
This commit is contained in:
@@ -5,12 +5,13 @@
|
||||
#include <vector>
|
||||
#include <regex>
|
||||
|
||||
#include "log_parsing.h"
|
||||
#include "log_parsing.hpp"
|
||||
|
||||
p_logs::p_logs(std::string log_path) {
|
||||
|
||||
parsed_logs::parsed_logs(std::string log_path) {
|
||||
std::ifstream file(log_path);
|
||||
if (!file.is_open()) {
|
||||
std::cerr << "Error loading " << log_path << std::endl;
|
||||
std::cerr << "Error loading " << log_path << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -19,8 +20,8 @@ parsed_logs::parsed_logs(std::string log_path) {
|
||||
std::string line;
|
||||
std::smatch match;
|
||||
|
||||
while (std::getline(file, line)) {
|
||||
if (std::regex_search(line, match, log_pattern)) {
|
||||
while (getline(file, line)) {
|
||||
if (regex_search(line, match, log_pattern)) {
|
||||
|
||||
Entry current_entry;
|
||||
current_entry.ip = match[1].str();
|
||||
@@ -55,34 +56,48 @@ parsed_logs::parsed_logs(std::string log_path) {
|
||||
file.close();
|
||||
}
|
||||
|
||||
std::string parsed_logs::entryx_ip(int x){
|
||||
std::string p_logs::entryx_ip(int x){
|
||||
return logs[x].ip;
|
||||
}
|
||||
|
||||
std::string parsed_logs::entryx_timestamp(int x){
|
||||
std::string p_logs::entryx_timestamp(int x){
|
||||
return logs[x].timestamp;
|
||||
}
|
||||
|
||||
std::string parsed_logs::entryx_request(int x){
|
||||
std::string p_logs::entryx_request(int x){
|
||||
return logs[x].request;
|
||||
}
|
||||
|
||||
std::string parsed_logs::entryx_status(int x){
|
||||
std::string p_logs::entryx_status(int x){
|
||||
return logs[x].status;
|
||||
}
|
||||
|
||||
std::string parsed_logs::entryx_bytes(int x){
|
||||
std::string p_logs::entryx_bytes(int x){
|
||||
return logs[x].bytes;
|
||||
}
|
||||
|
||||
std::string parsed_logs::entryx_referer(int x){
|
||||
std::string p_logs::entryx_referer(int x){
|
||||
return logs[x].referer;
|
||||
}
|
||||
|
||||
std::string parsed_logs::entryx_os(int x){
|
||||
std::string p_logs::entryx_os(int x){
|
||||
return logs[x].os;
|
||||
}
|
||||
|
||||
std::string parsed_logs::entryx_browser(int x){
|
||||
std::string p_logs::entryx_browser(int x){
|
||||
return logs[x].browser;
|
||||
}
|
||||
|
||||
void p_logs::print_logs() {
|
||||
for (const auto& log : logs) {
|
||||
std::cout << "IP: " << log.ip.c_str() << "\n"
|
||||
<< "Timestamp: " << log.timestamp.c_str() << "\n"
|
||||
<< "Request: " << log.request.c_str() << "\n"
|
||||
<< "Status: " << log.status.c_str() << "\n"
|
||||
<< "Bytes: " << log.bytes.c_str() << "\n"
|
||||
<< "Referer: " << log.referer.c_str() << "\n"
|
||||
<< "OS: " << log.os.c_str() << "\n"
|
||||
<< "Browser: " << log.browser.c_str() << "\n\n"
|
||||
<< "-----------------------------\n\n";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user