Main Page   Compound List   File List   Compound Members   File Members  

httpstats.C File Reference

#include <string>
#include <fstream>
#include "configuration.h"
#include "logrecord.h"
#include "stats.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])


Function Documentation

int main ( int argc,
char * argv[] )
 

Definition at line 13 of file httpstats.C.

00013                             {
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 }


httpstats-stage00 [ 7 April, 2001]