[Tutor] log parsing

Will Harris mosinu at gmail.com
Wed Nov 30 01:40:10 CET 2005


I am trying to work out doing a bit of log parsing in python. Below is the
code I have gotten so far, It works in an earlier version of this one but
this one doesn't print out the lines in my log files. Does anyone see
anything that I am missing here or can just point me in the direction to
look?
This iteration I am just trying to get it to let me specify the logs I want
to parse from the command line (later I want to sort all this out and put it
into a postgres database)

 <http://mail.python.org/pipermail/tutor/2002-September/017102.html>
#!/usr/bin/python
###

import sys
import re

###

USAGE = (sys.argv[0]) + ''' logfile logfile logfile '''
###

def hasAccept(s):
   return s.find('accept-n-log') != -1

def hasDrop(s):
   return s.find('drop-n-log') != -1

def main():
    if len(sys.argv) <= 1:
        print USAGE
        return 1

    for logs in sys.argv[1:]:
      open(logs)
      for line in logs:
         if hasAccept(line):
             print(line)

if __name__ == '__main__':
        main()

 <http://mail.python.org/pipermail/tutor/2002-September/017102.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051129/6016ce88/attachment.htm


More information about the Tutor mailing list