Main Page   Compound List   File List   Compound Members   File Members  

httpstats.C

Go to the documentation of this file.
00001 // $Id: httpstats.C,v 1.4 2001/04/13 05:45:44 dvermeir Exp $
00002 
00003 // httpstats main function
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 // 1. check arguments: there must be exactly 2 of them.
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 // 2. parse confiuration file. We will use a class Configuration that
00025 // will contain the configuration information. 
00026 // But firs, we attempt to open the file.
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 // 3. Process the log file line by line and process each line using config.
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 // A stats object probably must know about config.
00048 Stats      stats(config);  
00049 string     line;
00050 LogRecord  logrecord;
00051 // # of lines succesfully parsed
00052 int        n_lines_parsed(0); 
00053 // # of lines with errors 
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 

httpstats-stage00 [ 7 April, 2001]