Next / Previous / Contents / TCC Help System / NM Tech homepage

9. readLogFile(): Process one access log

This function reads one access log and adds any valid records to the accessSummary.

webstats.py
# - - -   r e a d L o g F i l e

def readLogFile ( accessSummary, fileName ):
    '''Process one access log.

      [ (accessSummary is an AccessSummary instance) and
        (fileName is a string) ->
          if fileName names a readable file ->
            accessSummary  :=  accessSummary with relevant
                records added from that file
            sys.stderr  +:=  error messages about invalid lines,
                if any
          else -> raise IOError ]
    '''
    #-- 1 --
    # [ if fileName names a readable file ->
    #     inFile  :=  that file, so opened
    #   else -> raise IOError ]
    inFile  =  open ( fileName )

For the function that turns an access log into a stream of PageGet instances, see Section 51.3, “scanAccessLog(): Scan an access log file”.

webstats.py
    #-- 2 --
    # [ accessSummary  :=  accessSummary + (records from inFile
    #       that are valid and pass AccessSummary's filters)
    #   sys.stderr  +:=  error messages about invalid lines
    #           from inFile, if any ]
    for pageGet in scanAccessLog ( inFile ):
        accessSummary.addPageGet ( pageGet )
    inFile.close()