Formatters

Formatters format the logs.

Contents:

pylog.formatters.fake_data(data_type)[source]
class pylog.formatters.BaseFormatter(config)[source]

Bases: object

generate_data()[source]
class pylog.formatters.CustomFormatter(config)[source]

Bases: pylog.formatters.BaseFormatter

generates log strings in a custom format

this is also the the formatter other formatters can rely on to generate application specific logs. see the ApacheAccessFormatter class for reference.

generate_data()[source]

returns a log string

for every item in the format list, if an item in the data dict corresponds with it and the field’s data equals “$RAND”, use faker to fake an item for it. else, choose one item from the list randomly. if there no item in the data to correspond with the format, it will just append to format’s field name to the log.

example:
 'CustomFormatter': {
     'format': ['name', ' - ', 'level'],
     'data': {
         'name': $RAND,
         'level': ['ERROR', 'DEBUG', 'INFO', 'CRITICAL'],
    }
}

the output of the above example might be:

Sally Fields - ERROR
or
Jason Banks - DEBUG
or
Danny Milwee - ERROR
or
...
class pylog.formatters.JsonFormatter(config)[source]

Bases: pylog.formatters.BaseFormatter

generates log strings in json format

generate_data()[source]

returns a json string

all fields in the data dict will be iterated over. if $RAND is set in one of the fields, random data will be generate_data for that field. If not, data will be chosen from the list.

example:
'JsonFormatter': {
    'data': {
        'date_time': '$RAND',
        'level': ['ERROR', 'DEBUG'],
        'address': '$RAND',
    }
},

the output of the above example might be:

{'date_time': '2006-11-05 13:31:09', 'name': 'Miss Nona Breitenberg DVM', 'level': 'ERROR'}  # NOQA
or
{'date_time': '1985-01-20 11:41:16', 'name': 'Almeda Lindgren', 'level': 'DEBUG'}  # NOQA
or
{'date_time': '1973-05-21 01:06:04', 'name': 'Jase Heaney', 'level': 'DEBUG'}  # NOQA
or
...
class pylog.formatters.ApacheAccessFormatter(config)[source]

Bases: pylog.formatters.CustomFormatter

class pylog.formatters.ApacheErrorFormatter(config)[source]

Bases: pylog.formatters.CustomFormatter