sawmill.handler.buffer

class sawmill.handler.buffer.Buffer(handler, trigger, limit=50, *args, **kw)[source]

Bases: sawmill.handler.base.Handler

Buffer log records and distribute to another handler on trigger.

Any log record handled by this handler will first be filtered and formatted by this handler before being added to the buffer.

The wrapped handler will still have opportunity to further filter and format the log records as required.

Note

The data returned by any registered formatter on this handler will be passed directly to the wrapped handler’s handle method. Therefore, it must be a valid Log record.

__init__(handler, trigger, limit=50, *args, **kw)[source]

Initialise handler with wrapped handler and trigger.

trigger should be a callable that accepts the new data being handled and the buffer contents (including the new data). It should return True if the wrapped handler should be called with the buffer else False.

limit will set the maximimum size of the buffer. When the buffer size exceeds the limit and new logs are added, logs will be removed from the opposite end

Note

By default the buffer is cleared after each successful trigger.

output(data)[source]

Output formatted data.

As data is eventually passed directly to other handlers’ handle methods, it should be a list of valid Log records.

reset()[source]

Reset buffer.