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