Documentation

DeduplicationHandler extends BufferHandler
in package

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.

Tags
author

Jordi Boggiano j.boggiano@seld.be

Table of Contents

Properties

$bubble  : bool
$buffer  : array<string|int, LogRecord>
$bufferLimit  : int
$bufferSize  : int
$deduplicationLevel  : Level
$deduplicationStore  : string
$flushOnOverflow  : bool
$gc  : bool
$handler  : HandlerInterface
$initialized  : bool
$level  : Level
$processors  : array<string|int, callable>
$time  : int

Methods

__construct()  : mixed
__destruct()  : mixed
__sleep()  : mixed
clear()  : void
Clears the buffer without flushing any messages down to the wrapped handler.
close()  : void
Closes the handler.
flush()  : void
getBubble()  : bool
Gets the bubbling behavior.
getFormatter()  : FormatterInterface
Gets the formatter.
getLevel()  : Level
Gets minimum logging level at which this handler will be triggered.
handle()  : bool
Handles a record.
handleBatch()  : void
Handles a set of records at once.
isHandling()  : bool
Checks whether the given record will be handled by this handler.
popProcessor()  : callable
pushProcessor()  : HandlerInterface
reset()  : void
setBubble()  : $this
Sets the bubbling behavior.
setFormatter()  : HandlerInterface
Sets the formatter.
setLevel()  : $this
Sets minimum logging level at which this handler will be triggered.
buildDeduplicationStoreEntry()  : string
isDuplicate()  : bool
If there is a store entry older than e.g. a day, this method should set `$this->gc` to `true` to trigger garbage collection.
processRecord()  : LogRecord
resetProcessors()  : void
collectLogs()  : void

Properties

$processors

protected array<string|int, callable> $processors = []
Tags
phpstan-var

array<(callable(LogRecord): LogRecord)|ProcessorInterface>

Methods

__construct()

public __construct(HandlerInterface $handler[, string|null $deduplicationStore = null ][, int|string|Level|LogLevel::* $deduplicationLevel = Level::Error ][, int $time = 60 ][, bool $bubble = true ]) : mixed
Parameters
$handler : HandlerInterface

Handler.

$deduplicationStore : string|null = null

The file/path where the deduplication log should be kept

$deduplicationLevel : int|string|Level|LogLevel::* = Level::Error

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

$time : int = 60

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

$bubble : bool = true

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

Tags
phpstan-param

value-ofLevel::VALUES|value-ofLevel::NAMES|Level|LogLevel::* $deduplicationLevel

clear()

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

public clear() : void

close()

Closes the handler.

public close() : void
Tags
inheritDoc

getBubble()

Gets the bubbling behavior.

public getBubble() : bool
Return values
bool

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

getLevel()

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

public getLevel() : Level
Return values
Level

handle()

Handles a record.

public handle(LogRecord $record) : bool
Parameters
$record : LogRecord

The record to handle

Tags
inheritDoc
Return values
bool

true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.

handleBatch()

Handles a set of records at once.

public handleBatch(array<string|int, mixed> $records) : void
Parameters
$records : array<string|int, mixed>

The records to handle

Tags
inheritDoc

isHandling()

Checks whether the given record will be handled by this handler.

public isHandling(LogRecord $record) : bool
Parameters
$record : LogRecord

Partial log record having only a level initialized

Tags
inheritDoc
Return values
bool

setBubble()

Sets the bubbling behavior.

public setBubble(bool $bubble) : $this
Parameters
$bubble : bool

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

Return values
$this

setLevel()

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

public setLevel(Level|LogLevel::* $level) : $this
Parameters
$level : Level|LogLevel::*

Level or level name

Tags
phpstan-param

value-ofLevel::VALUES|value-ofLevel::NAMES|Level|LogLevel::* $level

Return values
$this

buildDeduplicationStoreEntry()

protected buildDeduplicationStoreEntry(LogRecord $record) : string
Parameters
$record : LogRecord
Return values
string

The given record serialized as a single line of text

isDuplicate()

If there is a store entry older than e.g. a day, this method should set `$this->gc` to `true` to trigger garbage collection.

protected isDuplicate(array<string|int, string> $store, LogRecord $record) : bool
Parameters
$store : array<string|int, string>

The deduplication store

$record : LogRecord
Return values
bool

        
On this page

Search results