ANNOUNCE: Apache::LogRegex 1.0

From: Peter Hickman (peter_at_semantico.com)
Date: 01/26/04

  • Next message: Peter Hickman: "ANNOUNCE: Graph::Timeline and Graph::Timeline::GD 1.0"
    Date: Mon, 26 Jan 2004 12:45:20 +0000
    
    

    Apache::LogRegex - Parse a line from an Apache logfile into a hash

    This document refers to version 1.00 of Apache::LogRegex, released
    January 22nd, 2004

       use Apache::LogRegex;

       my $lr;

       eval { $lr = Apache::LogRegex->new($log_format) };
       die "Unable to parse log line: $@" if ($@);

       my %data;

       while ( my $line_from_logfile = <> ) {
         eval { %data = $lr->parse($line_from_logfile); };
         if (%data) {
           # We have data to process
         } else {
           # We could not parse this line
         }
       }

    Designed as a simple class to parse Apache log files. It will construct
    a regex that will parse the given log file format and can then parse
    lines from the log file line by line returning a hash of each line.

    The field names of the hash are derived from the log file format. Thus
    if the format is '%a %t \"%r\" %s %b %T \"%{Referer}i\" ...' then the
    keys of the hash will be %a, %t, %r, %s, %b, %T and %{Referer}i.

    Should these key names be unusable, as I guess they probably are, then
    subclass and provide an override rename_this_name() method that can
    rename the keys before they are added in the array of field names.

    At a CPAN near you soon.


  • Next message: Peter Hickman: "ANNOUNCE: Graph::Timeline and Graph::Timeline::GD 1.0"