sawmill.formatter.template

class sawmill.formatter.template.Template(template, missing_key='')[source]

Bases: sawmill.formatter.base.Formatter, string.Formatter

Format logs according to a template.

ERROR = '__ERROR__'
__init__(template, missing_key='')[source]

Initialise formatter with template.

missing_key determines how to handle a missing key when formatting a log. If set to ERROR then an error will be raised for any key referenced in the template that is missing from the log. Any other value will be used as the substitute for the missing value. The default is an empty string.

Note

The template is applied once per processed log.

format(logs)[source]

Return formatted data representing log.

get_field(field_name, args, kwargs)[source]

Convert and return field_name to an object to be formatted.

Note

Based on Python’s string.Formatter.get_field source.