duct.logs

duct.logs.follower

class duct.logs.follower.LogFollower(logfile, parser=None, tmp_path='/var/lib/duct/', history=False)[source]

Bases: object

Provides a class for following log files between runs

Parameters:
  • logfile (str) – Full path to logfile

  • parser (str) – Optional parser method for log lines

  • tmp_path (str) – Temporary path used to store position markers

  • history (str) – If True the log is read from the start instead of tailed unless its already been read

cleanStore()[source]

Clear up the log position store

get(max_lines=None)[source]

Returns a big list of all log lines since the last run

get_fn(fn, max_lines=None)[source]

Passes each parsed log line to fn This is a better idea than storing a giant log file in memory

readLast()[source]

Read the latest changes in the file

storeLast()[source]

Persist the current position in the file

duct.logs.parsers

class duct.logs.parsers.ApacheLogParser(fmt)[source]

Bases: object

Parses Apache log format

Adapted from http://code.google.com/p/apachelog

Parameters:

format (str) – Apache log format definition eg r’%h %l %u %t “%r” %>s %b “%{Referer}i” “%{User-Agent}i”’ or one of ‘common’, ‘vhcommon’ or ‘combined’

alias(field)[source]

Alias a field

names()[source]

Returns the field names the parser extracted from the input format (a list)

parse(line)[source]

Parses a single line from the log file and returns a dictionary of it’s contents.

Raises and exception if it couldn’t parse the line

pattern()[source]

Returns the compound regular expression the parser extracted from the input format (a string)

exception duct.logs.parsers.ApacheLogParserError[source]

Bases: Exception

Appache log parsing error