Random thoughts shooting out of volatile mind
A Small Python module to parse Apache Log lines
This is my first module written in Python. I wanted to extract the information from Apache access log line so searched for existing modules, even though I found one i felt logic is too complicated, I wanted a very simple module. So thought why don't I write my own module to parse log lines. Since I designed this to meet my requirements it may not be a complete module. It can parse and give you information from the Apache access log lines which is either common or combined format. If you don't know what is common and combined format refer this documentation. This module doesn't validate the lines to check if its really Apache log lines it depends on user to pass correct line. I've also added another simple module which can get you information from error log line. The module is available in gitorious

Below is the code which shows how to use this module.
import apachelogparser as a
f = open("/var/log/apache2/access.log") #change it to suit log location in your machine
line = f.readline()
log_parser = a.ApacheAccessLogParser()
The fields of log_parser object will be filled with information extracted from the line. Please refer the README in documentation for information on the field. Similarly you can extract information from the error log. Well hope this module helps you :). Soon will be publishing the project for which I wrote this module till then.
Posted by: copyninja on Sunday, 27 June 2010

blog comments powered by Disqus
Fork me on GitHub