View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Barbie > Regexp-Log-Common-0.09 > Regexp::Log::Common



Annotate this POD


Open  0
View/Report Bugs
Module Version: 0.09   Source   Latest Release: Regexp-Log-Common-0.10


Regexp::Log::Common - A regular expression parser for the Common Log Format


    my $foo = Regexp::Log::Common->new(
        format  => '%date %request',
        capture => [qw( ts request )],

    # the format() and capture() methods can be used to set or get
    $foo->format('%date %request %status %bytes');
    $foo->capture(qw( ts req ));

    # this is necessary to know in which order
    # we will receive the captured fields from the regexp
    my @fields = $foo->capture;

    # the all-powerful capturing regexp :-)
    my $re = $foo->regexp;

    while (<>) {
        my %data;
        @data{@fields} = /$re/;    # no need for /o, it's a compiled regexp

        # now munge the fields


Regexp::Log::Common uses Regexp::Log as a base class, to generate regular expressions for performing the usual data munging tasks on log files that cannot be simply split().

This specific module enables the computation of regular expressions for parsing the log files created using the Common Log Format. An example of this format are the logs generated by the httpd web server using the keyword 'common'.

The module also allows for the use of the Extended Common Log Format.

For more information on how to use this module, please see Regexp::Log.


Enables simple parsing of log files created using the Common Log Format or the Extended Common Log Format, such as the logs generated by the httpd/Apache web server using the keyword 'common'.


Common Log Format

The Common Log Format is made up of several fields, each delimited by a single space.

Extended Common Log Format

The Extended Common Log Format is made up of several fields, each delimited by a single space.

Custom Log Formats

There are any number of LogFormat lines you can define, and although this module doesn't define all the formats, you can specify your own customer format to extract fields as necessary.


There are several format fields available, although this module does not them all. The ones it does currently support are as follows:

    shorthand       => longhand (if applicable)

    '%a'            => '%remoteip'
    '%A'            => '%localip'
    '%B'            => '%bytes'
    '%b'            => '%bytes'
    '%D'            => '%time'
    '%F'            => '%filename'
    '%h'            => '%host' or '%remotehost'
    '%H'            => '%protcol'
    '%k'            => '%keepalive'
    '%l'            => '%logname' or '%rfc'
    '%m'            => '%method'
    '%p'            => '%port'
    '%P'            => '%pid'
    '%q'            => '%queryatring'
    '%r'            => '%request'
    '%s'            => '%status'
    '%t'            => '%date', also '%ts' (excluding surrounding '[]')
    '%T'            => '%seconds'
    '%u'            => '%authuser'
    '%U'            => '%request' or '%req' (excluding surrounding '"')
    '%v'            => '%servername'
    '%V'            => '%servername'
    '%X'            => '%connection'
    %{Foobar}i fields
    '%referer'      => or '%ref' (excluding surrounding '"')
    '%useragent'    => or '%ua' (excluding surrounding '"')

For a more detail explanation, please see the Apache Log Formats documentation at


There are no known bugs at the time of this release. However, if you spot a bug or are experiencing difficulties that are not explained within the POD documentation, please submit a bug to the RT system (see link below). However, it would help greatly if you are able to pinpoint problems or even supply a patch.

Fixes are dependent upon their severity and my availability. Should a fix not be forthcoming, please feel free to (politely) remind me by sending an email to .





BooK for initially putting the idea into my head, and the thread on a perl message board, that wanted the help that was solved with this exact module.


  Barbie <>
  for Miss Barbell Productions, L<>


  Copyright (C) 2005-2014 Barbie for Miss Barbell Productions.

  This distribution is free software; you can redistribute it and/or
  modify it under the Artistic License v2.
syntax highlighting: