00001
00002
00003
00004
00005 #include <string>
00006 #include <fstream>
00007
00008 #include "configuration.h"
00009 #include "logrecord.h"
00010 #include "stats.h"
00011
00012 int
00013 main(int argc,char* argv[]) {
00014 const string usage("httpstats configfile logfile");
00015
00016 if (argc!=3) {
00017 cerr << "Usage: " << usage << endl;
00018 return 1;
00019 }
00020
00021 string config_file_name(argv[1]);
00022 string log_file_name(argv[2]);
00023
00024
00025
00026
00027 ifstream config_file(config_file_name.c_str());
00028 if (!config_file) {
00029 cerr << "Cannot open configuration file \"" << config_file_name << "\"" << endl;
00030 return 1;
00031 }
00032
00033 Configuration config;
00034 if (!config.parse(config_file)) {
00035 cerr << "Fatal error in configuration file \"" << config_file_name << "\"" << endl;
00036 return 1;
00037 }
00038
00039
00040 ifstream log_file(log_file_name.c_str());
00041 if (!log_file) {
00042 cerr << "Cannot open log file \"" << log_file_name << "\"" << endl;
00043 return 1;
00044 }
00045
00046
00047
00048 Stats stats(config);
00049 string line;
00050 LogRecord logrecord;
00051
00052 int n_lines_parsed(0);
00053
00054 int n_error_lines(0);
00055
00056 while (getline(log_file,line)) {
00057 if (parse_line(line,logrecord)) {
00058 stats.add(logrecord);
00059 ++n_lines_parsed;
00060 }
00061 else
00062 ++n_error_lines;
00063 }
00064
00065 cerr << n_lines_parsed << " lines processed, "
00066 << n_error_lines << " lines had errors" << endl;
00067 }
00068