forked from flrnull/http-logs-analyzer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
executable file
·47 lines (46 loc) · 1.4 KB
/
main.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 <stdlib.h>
#include <memory>
#include <iostream>
#include <fstream>
#include "Config.h"
#include "Debug.h"
#include "Result.h"
#include "Parser.h"
#include "regex_functions.h"
int main(int argc, char **argv)
{
// Init and validate params
std::auto_ptr<Config> config(Config::getInstance());
config->parseArgs(argc, argv);
config->debug();
std::ifstream logFile(config->logName.c_str(), std::ifstream::in);
if (!logFile) {
Debug::print("Error: file " + config->logName + " is not exists!");
exit(1);
}
// Collect data
if (config->debugMode) {
Debug::print("Start reading file...");
}
std::string logLine;
Parser parser(config.get());
// Create regex
LogRegexTexts logRegExpsTexts;
LogRegexCompiled logRegExpsCompiled;
logRegexTextsFill(&logRegExpsTexts, config.get());
logRegexForCompileFill(&logRegExpsCompiled);
logRegexCompileAll(&logRegExpsTexts, &logRegExpsCompiled, config.get());
// Parse file
while(std::getline(logFile, logLine)) {
parser.parse(logLine, &logRegExpsCompiled);
}
if (config->debugMode) {
Debug::print("End reading file...");
}
// Calc unique users and urls count
Result::visitors = Result::ipAgentMap.size();
Result::urls = Result::urlMap.size();
// Result
Result::display();
return 0;
}