1Apache::LogRegex(3)   User Contributed Perl Documentation  Apache::LogRegex(3)
2
3
4

NAME

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

VERSION

9       This document refers to version 1.4 of Apache::LogRegex, released Octo‐
10       ber 21st 2006
11

SYNOPSIS

13         use Apache::LogRegex;
14
15         my $lr;
16
17         eval { $lr = Apache::LogRegex->new($log_format) };
18         die "Unable to parse log line: $@" if ($@);
19
20         my %data;
21
22         while ( my $line_from_logfile = <> ) {
23             eval { %data = $lr->parse($line_from_logfile); };
24             if (%data) {
25                 # We have data to process
26             } else {
27                 # We could not parse this line
28             }
29         }
30

DESCRIPTION

32       Overview
33
34       Designed as a simple class to parse Apache log files. It will construct
35       a regex that will parse the given log file format and can then parse
36       lines from the log file line by line returning a hash of each line.
37
38       The field names of the hash are derived from the log file format. Thus
39       if the format is '%a %t \"%r\" %s %b %T \"%{Referer}i\" ...' then the
40       keys of the hash will be %a, %t, %r, %s, %b, %T and %{Referer}i.
41
42       Should these key names be unusable, as I guess they probably are, then
43       subclass and provide an override rename_this_name() method that can
44       rename the keys before they are added in the array of field names.
45
46       Constructors and initialization
47
48       Apache::LogRegex->new( FORMAT )
49           Returns a Apache::LogRegex object that can parse a line from an
50           Apache logfile that was written to with the FORMAT string. The FOR‐
51           MAT string is the CustomLog string from the httpd.conf file.
52
53       Class and object methods
54
55       parse( LINE )
56           Given a LINE from an Apache logfile it will parse the line and
57           return a hash of all the elements of the line indexed by their for‐
58           mat. If the line cannot be parsed an empty hash will be returned.
59
60       names()
61           Returns a list of field names that were extracted from the data.
62           Such as '%a', '%t' and '%r' from the above example.
63
64       regex()
65           Returns a copy of the regex that will be used to parse the log
66           file.
67
68       rename_this_name( NAME )
69           Use this method to rename the keys that will be used in the
70           returned hash.  The initial NAME is passed in and the method should
71           return the new name.
72

ENVIRONMENT

74       Perl 5
75

DIAGNOSTICS

77       The only problem I can foresee is the various custom time formats but
78       providing that they are encased in '[' and ']' all should be fine.
79
80       Apache::LogRegex->new() takes 1 argument
81           When the constructor is called it requires one argument. This mes‐
82           sage is given if more or less arguments were supplied.
83
84       Apache::LogRegex->new() argument 1 (FORMAT) is undefined
85           The correct number of arguments were supplied with the constructor
86           call, however the first argument, FORMAT, was undefined.
87
88       Apache::LogRegex->parse() takes 1 argument
89           When the method is called it requires one argument. This message is
90           given if more or less arguments were supplied.
91
92       Apache::LogRegex->parse() argument 1 (LINE) is undefined
93           The correct number of arguments were supplied with the method call,
94           however the first argument, LINE, was undefined.
95
96       Apache::LogRegex->names() takes no argument
97           When the method is called it requires no arguments. This message is
98           given if some arguments were supplied.
99
100       Apache::LogRegex->regex() takes no argument
101           When the method is called it requires no arguments. This message is
102           given if some arguments were supplied.
103

BUGS

105       None so far
106

FILES

108       None
109

SEE ALSO

111       mod_log_config for a description of the Apache format commands
112

AUTHOR

114       Peter Hickman (peterhi@ntlworld.com)
115
117       Copyright (c) 2004, Peter Hickman. All rights reserved. This module is
118       free software. It may be used, redistributed and/or modified under the
119       same terms as Perl itself.
120
121
122
123perl v5.8.8                       2006-10-21               Apache::LogRegex(3)
Impressum