\Monolog\HandlerDeduplicationHandler

Simple handler wrapper that deduplicates log records across multiple requests

It also includes the BufferHandler functionality and will buffer all messages until the end of the request or flush() is called.

This works by storing all log records' messages above $deduplicationLevel to the file specified by $deduplicationStore. When further logs come in at the end of the request (or when flush() is called), all those above $deduplicationLevel are checked against the existing stored logs. If they match and the timestamps in the stored log is not older than $time seconds, the new log record is discarded. If no log record is new, the whole data set is discarded.

This is mainly useful in combination with Mail handlers or things like Slack or HipChat handlers that send messages to people, to avoid spamming with the same message over and over in case of a major component failure like a database server being down which makes all requests fail in the same way.

Summary

Methods
Properties
Constants
__construct()
handle()
flush()
__destruct()
close()
clear()
reset()
setFormatter()
getFormatter()
pushProcessor()
popProcessor()
isHandling()
setLevel()
getLevel()
setBubble()
getBubble()
handleBatch()
__sleep()
No public properties found
No constants found
processRecord()
resetProcessors()
$handler
$bufferSize
$bufferLimit
$flushOnOverflow
$buffer
$initialized
$processors
$level
$bubble
$deduplicationStore
$deduplicationLevel
$time
N/A
isDuplicate()
collectLogs()
appendRecord()
$gc
N/A

Properties

$handler

$handler : \Monolog\Handler\HandlerInterface

Type

HandlerInterface

$bufferSize

$bufferSize : int

Type

int

$bufferLimit

$bufferLimit : int

Type

int

$flushOnOverflow

$flushOnOverflow : bool

Type

bool

$buffer

$buffer : \Monolog\Handler\Record[]

Type

Record[]

$initialized

$initialized : bool

Type

bool

$processors

$processors : callable[]

Type

callable[]

$level

$level : int

Type

int

$bubble

$bubble : bool

Type

bool

$deduplicationStore

$deduplicationStore : string

Type

string

$deduplicationLevel

$deduplicationLevel : \Monolog\Handler\Level

Type

\Monolog\Handler\Level —

$time

$time : int

Type

int

$gc

$gc : bool

Type

bool

Methods

__construct()

__construct(\Monolog\Handler\HandlerInterface  $handler, string  $deduplicationStore = null, string|int  $deduplicationLevel = Logger::ERROR, int  $time = 60, bool  $bubble = true) : mixed

Parameters

\Monolog\Handler\HandlerInterface $handler

Handler.

string $deduplicationStore

The file/path where the deduplication log should be kept

string|int $deduplicationLevel

The minimum logging level for log records to be looked at for deduplication purposes

int $time

The period (in seconds) during which duplicate entries should be suppressed after a given log is sent through

bool $bubble

Whether the messages that are handled can bubble up the stack or not

Returns

mixed —

handle()

handle(array  $record) : bool

{@inheritDoc}

Parameters

array $record

Returns

bool —

flush()

flush() : void

__destruct()

__destruct() : mixed

Returns

mixed —

close()

close() : void

Closes the handler.

clear()

clear() : void

Clears the buffer without flushing any messages down to the wrapped handler.

reset()

reset() : void

setFormatter()

setFormatter(\Monolog\Formatter\FormatterInterface  $formatter) : \Monolog\Handler\HandlerInterface

Sets the formatter.

Parameters

\Monolog\Formatter\FormatterInterface $formatter

Returns

\Monolog\Handler\HandlerInterface —

self

getFormatter()

getFormatter() : \Monolog\Formatter\FormatterInterface

Gets the formatter.

Returns

\Monolog\Formatter\FormatterInterface —

pushProcessor()

pushProcessor(callable  $callback) : \Monolog\Handler\HandlerInterface

{@inheritDoc}

Parameters

callable $callback

Returns

\Monolog\Handler\HandlerInterface —

popProcessor()

popProcessor() : callable

{@inheritDoc}

Returns

callable —

isHandling()

isHandling(array  $record) : bool

{@inheritDoc}

Parameters

array $record

Returns

bool —

setLevel()

setLevel(mixed  $level) : self

Sets minimum logging level at which this handler will be triggered.

Parameters

mixed $level

Returns

self —

getLevel()

getLevel() : int

Gets minimum logging level at which this handler will be triggered.

Returns

int —

setBubble()

setBubble(bool  $bubble) : self

Sets the bubbling behavior.

Parameters

bool $bubble

true means that this handler allows bubbling. false means that bubbling is not permitted.

Returns

self —

getBubble()

getBubble() : bool

Gets the bubbling behavior.

Returns

bool —

true means that this handler allows bubbling. false means that bubbling is not permitted.

handleBatch()

handleBatch(array  $records) : void

Handles a set of records at once.

Parameters

array $records

The records to handle (an array of record arrays)

__sleep()

__sleep() : mixed

Returns

mixed —

processRecord()

processRecord(array  $record) : array

Processes a record.

Parameters

array $record

Returns

array —

resetProcessors()

resetProcessors() : void

isDuplicate()

isDuplicate(array  $record) : bool

Parameters

array $record

Returns

bool —

collectLogs()

collectLogs() : void

appendRecord()

appendRecord(array  $record) : void

Parameters

array $record