00020 {
00021
00022
00023 try {
00024
00025 if (argc<2 || argc>3) {
00026 cerr << "Usage: " << usage << endl;
00027 return 1;
00028 }
00029
00030 string log_file_name(argv[1]);
00031
00032
00033
00034
00035 istream* config_file(0);
00036 string config_file_name((argc==3) ? argv[2] : "default");
00037
00038 if (argc==3) {
00039
00040
00041 config_file = new ifstream(config_file_name.c_str());
00042
00043 if (!*config_file) {
00044 cerr << "Cannot open configuration file \""
00045 << config_file_name << "\"" << endl;
00046 return 1;
00047 }
00048 }
00049 else
00050 config_file = new istrstream(default_config_text.data(),
00051 default_config_text.size());
00052
00053
00054
00055 Configuration config;
00056 unsigned int err_lineno(config.parse(*config_file));
00057 if (err_lineno) {
00058 cerr << "Error on line " << err_lineno
00059 << " in configuration file \"" << config_file_name << "\"" << endl;
00060 return 1;
00061 }
00062
00063 delete config_file; config_file = 0;
00064
00065 cerr << config << endl;
00066
00067 ifstream log_file(log_file_name.c_str());
00068 if (!log_file) {
00069 cerr << "Cannot open log file \"" << log_file_name << "\"" << endl;
00070 return 1;
00071 }
00072
00073 Stats stats(config);
00074 const Expression* select(config.select());
00075 string line;
00076 LogRecord logrecord;
00077 int n_lines_parsed(0);
00078 int n_lines_selected(0);
00079 int n_error_lines(0);
00080
00081
00082
00083 while (getline(log_file,line)) {
00084 if (logrecord.parse_line(line)) {
00085 if (select) {
00086 if (select->eval(logrecord)) {
00087 ++n_lines_selected;
00088 stats.add(logrecord);
00089 }
00090 }
00091 else {
00092 stats.add(logrecord);
00093 ++n_lines_selected;
00094 }
00095 ++n_lines_parsed;
00096 }
00097 else
00098 ++n_error_lines;
00099 }
00100
00101 cerr << "// Generate statistics output." << endl;
00102 cout << stats;
00103
00104
00105 cerr << n_lines_parsed << " lines processed, "
00106 << n_lines_selected << " lines selected, "
00107 << n_error_lines << " lines had errors" << endl;
00108 }
00109 catch (exception& e) {
00110 cerr << e.what() << endl;
00111 }
00112 }