1
This module can parse lines of Apache Access Log or Error log and provide you with infromation as object of class ApacheAccessLogParser or ApacheErrorLogParser.
2
3
The log format should be in the format as mentioned in this document http://httpd.apache.org/docs/2.1/logs.html
4
5
6
Below is description of each class
7
    ApacheAccessLogParser
8
        |
9
        |
10
        |- ip_address
11
        |- client_identity
12
        |- user_id
13
        |- date
14
        |- request
15
        |- response
16
        |- response_size
17
        |- referer
18
        |- user_agent
19
        
20
These are the standard fields that can be found in Access Log of apache which is either in common or combined format. This class can handle both common and combined format without any issues.
21
22
   ApacheErrorLogParser
23
        |
24
        |
25
        |- date
26
        |- type
27
        |- description
28
        |- client_ip
29
        
30
These are the field which I felt can be easily extracted from the error log line. Basically some time only 3 fields can be accessed but if description contains string client then ip address will be associated with it, in that case client_ip will contain that ip address else it will be None
31
32
Usage:
33
import apachelogparser as a
34
35
alog = a.ApacheAccessLogParser()
36
f = open("/var/www/log/apache2/access.log") # change this to suit the location of access log in your machine
37
aline = f.readline()
38
alog.parse(line)
39
40
Now the alog object contains the infromation from the line variable. Similarly you can parse the error log file.
41
42
P.S : This module is not intelligent enough to validate and detect lines which are not from access / error log. So its users duty to pass proper log lines to this module. I may add validation error handling in future, since I created this for my personal use I didn't feel like adding it ;).