diff --git a/log_parsing/log_parsing.cpp b/log_parsing/log_parsing.cpp index 5d3f54b..2dedfeb 100644 --- a/log_parsing/log_parsing.cpp +++ b/log_parsing/log_parsing.cpp @@ -5,12 +5,13 @@ #include #include -#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"; + } } \ No newline at end of file diff --git a/log_parsing/log_parsing.hpp b/log_parsing/log_parsing.hpp index ffd6927..4151fc1 100644 --- a/log_parsing/log_parsing.hpp +++ b/log_parsing/log_parsing.hpp @@ -24,7 +24,7 @@ struct Entry { std::string browser; }; -class parsed_logs { +class p_logs { private: Entry entry; std::vector logs; @@ -35,7 +35,7 @@ public: * Detailed explanation: This function takes in the absolute path to a .log file and parses the lines into individual "Entry"s. These Entrys are then stored into a vector that can then be accessed via getter functions. * @param string */ - parsed_logs(std::string); + p_logs(std::string); /** * @brief Getter function for a specific Entry's IP @@ -100,4 +100,10 @@ public: * @return std::string */ std::string entryx_browser(int); + + /** + * @brief Prints all parsed log entries + * + */ + void print_logs(); }; \ No newline at end of file diff --git a/main.cpp b/main.cpp index 312f870..558c9d0 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,7 @@ - +#include "log_parsing/log_parsing.hpp" int main(){ - -} \ No newline at end of file + p_logs logs("C:\\Users\\lewis\\Desktop\\Code\\parselog_cli\\test_logs\\access.log"); + logs.print_logs(); + return 0; +} + diff --git a/parselog_cli.exe b/parselog_cli.exe new file mode 100644 index 0000000..db181ab Binary files /dev/null and b/parselog_cli.exe differ diff --git a/access.log b/test_logs/access.log similarity index 100% rename from access.log rename to test_logs/access.log diff --git a/accesslog.log b/test_logs/accesslog.log similarity index 100% rename from accesslog.log rename to test_logs/accesslog.log