00015 {
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 cerr << config << endl;
00045
00046 ifstream log_file(log_file_name.c_str());
00047 if (!log_file) {
00048 cerr << "Cannot open log file \"" << log_file_name << "\"" << endl;
00049 return 1;
00050 }
00051
00052 Stats stats(config);
00053 const Expression* select(config.select());
00054 string line;
00055 LogRecord logrecord;
00056 int n_lines_parsed(0);
00057 int n_lines_selected(0);
00058 int n_error_lines(0);
00059
00060
00061
00062 while (getline(log_file,line)) {
00063 if (logrecord.parse_line(line)) {
00064 if (select) {
00065 if (select->eval(logrecord)) {
00066 ++n_lines_selected;
00067 stats.add(logrecord);
00068 }
00069 }
00070 else {
00071 stats.add(logrecord);
00072 ++n_lines_selected;
00073 }
00074 ++n_lines_parsed;
00075 }
00076 else
00077 ++n_error_lines;
00078 }
00079
00080 cerr << "// Generate statistics output." << endl;
00081 cout << stats;
00082
00083
00084 cerr << n_lines_parsed << " lines processed, "
00085 << n_lines_selected << " lines selected, "
00086 << n_error_lines << " lines had errors" << endl;
00087 }
00088 catch (exception& e) {
00089 cerr << e.what() << endl;
00090 }
00091 }