Python Package Docs

Templates

class tabulog.Template(template_string=None, file=None, classes=[], formatters={})

This is the core processor of logs. A Template object stores all the necessary information about the tabulog template string and the parser classes used within that template.

Templates can be created either by passing the tabulog template string and parser classes directly, or by storing the template string and class definitions in a single yaml file.

Attributes:
  • template (str): tabulog template string
  • classes (dict): :class:Parser objects to be used with the fields in the template
__init__(template_string=None, file=None, classes=[], formatters={})

Template constructor

Args:
  • tempalte_string (str): The tabulog template string
  • file (str): Name of a YAML file containing the tabulog string and class definitions
  • classes (list): List of Parser objects to be used with template. Ignored if using a template file.
  • formatters (dict): Dictionary of formatter functions to associate with the classes defined in file. Ignored if using a template_string.
tabulate(text)

Tabulate a list of strings (representing lines in a log file) into a Pandas DataFrame.

Args:
  • text(list): List of strings to be tabulated.
>>> t.tabulate('https://www.example.com/ - 200')
                        url  status
0  https://www.example.com/     200

Parsers

class tabulog.Parser(pattern, formatter=<function <lambda>>, name=None)

This is a helper class that represents a given field in the tabulog template.

Parser objects have a regex string (pattern) to match for in the record, a formatter function which takes the extracted text for the field and modifies it in some way (ex. cast to integer, make lowercase, etc.), and an optional name.

Attributes:
  • pattern (str): regex string to match on in the template
  • formatter (callable): Callable (usually a function or lambda expression) to modify the field after extraction
  • name (str): optional name for identification
__init__(pattern, formatter=<function <lambda>>, name=None)

Parser constructor

Args:
  • pattern (str): regex string to match on in the template
  • formatter (callable): Callable (usually a function or lambda expression) to modify the field after extraction
  • name (str): optional name for identification

Other Functions

tabulog.default_classes()

A dictionary of default Parser classes provided ‘out-of-the-box’.

By ‘classes’ here we mean Parser objects that come predefined with a defining regex string, and possibly a meaningful formatter function.

Returns:
A dictionary of Parser objects
>>> default_classes()
{'ip': Parser('[0-9]{1,3}(\.[0-9]{1,3}){3}', <function <lambda> at 0x7f492c4426a8>, 'ip')...