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
Table of Contents
- $bubble : mixed
- $buffer : mixed
- $bufferLimit : mixed
- $bufferSize : mixed
- $deduplicationLevel : int
- $deduplicationStore : string
- $flushOnOverflow : mixed
- $formatter : FormatterInterface
- $handler : mixed
- $initialized : mixed
- $level : mixed
- $processors : mixed
- $time : int
- $gc : bool
- __construct() : mixed
- __destruct() : mixed
- clear() : mixed
- Clears the buffer without flushing any messages down to the wrapped handler.
- close() : mixed
- Closes the handler.
- flush() : mixed
- getBubble() : bool
- Gets the bubbling behavior.
- getFormatter() : FormatterInterface
- Gets the formatter.
- getLevel() : int
- Gets minimum logging level at which this handler will be triggered.
- handle() : mixed
- {@inheritdoc}
- handleBatch() : mixed
- Handles a set of records at once.
- isHandling() : bool
- Checks whether the given record will be handled by this handler.
- popProcessor() : callable
- Removes the processor on top of the stack and returns it.
- pushProcessor() : self
- Adds a processor in the stack.
- reset() : mixed
- setBubble() : self
- Sets the bubbling behavior.
- setFormatter() : self
- Sets the formatter.
- setLevel() : self
- Sets minimum logging level at which this handler will be triggered.
- getDefaultFormatter() : FormatterInterface
- Gets the default formatter.
- appendRecord() : mixed
- collectLogs() : mixed
- isDuplicate() : mixed
Properties
$bubble
protected
mixed
$bubble
= true
$buffer
protected
mixed
$buffer
= array()
$bufferLimit
protected
mixed
$bufferLimit
$bufferSize
protected
mixed
$bufferSize
= 0
$deduplicationLevel
protected
int
$deduplicationLevel
$deduplicationStore
protected
string
$deduplicationStore
$flushOnOverflow
protected
mixed
$flushOnOverflow
$formatter
protected
FormatterInterface
$formatter
$handler
protected
mixed
$handler
$initialized
protected
mixed
$initialized
= false
$level
protected
mixed
$level
= MonologLogger::DEBUG
$processors
protected
mixed
$processors
= array()
$time
protected
int
$time
$gc
private
bool
$gc
= false
Methods
__construct()
public
__construct(HandlerInterface $handler[, string $deduplicationStore = null ][, int $deduplicationLevel = Logger::ERROR ][, int $time = 60 ][, bool $bubble = true ]) : mixed
Parameters
- $handler : HandlerInterface
-
Handler.
- $deduplicationStore : string = null
-
The file/path where the deduplication log should be kept
- $deduplicationLevel : int = Logger::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
Return values
mixed —__destruct()
public
__destruct() : mixed
Return values
mixed —clear()
Clears the buffer without flushing any messages down to the wrapped handler.
public
clear() : mixed
Return values
mixed —close()
Closes the handler.
public
close() : mixed
This will be called automatically when the object is destroyed
Return values
mixed —flush()
public
flush() : mixed
Return values
mixed —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.
getFormatter()
Gets the formatter.
public
getFormatter() : FormatterInterface
Return values
FormatterInterface —getLevel()
Gets minimum logging level at which this handler will be triggered.
public
getLevel() : int
Return values
int —handle()
{@inheritdoc}
public
handle(array<string|int, mixed> $record) : mixed
Parameters
- $record : array<string|int, mixed>
Return values
mixed —handleBatch()
Handles a set of records at once.
public
handleBatch(array<string|int, mixed> $records) : mixed
Parameters
- $records : array<string|int, mixed>
-
The records to handle (an array of record arrays)
Return values
mixed —isHandling()
Checks whether the given record will be handled by this handler.
public
isHandling(array<string|int, mixed> $record) : bool
Parameters
- $record : array<string|int, mixed>
-
Partial log record containing only a level key
Return values
bool —popProcessor()
Removes the processor on top of the stack and returns it.
public
popProcessor() : callable
Return values
callable —pushProcessor()
Adds a processor in the stack.
public
pushProcessor(mixed $callback) : self
Parameters
- $callback : mixed
Return values
self —reset()
public
reset() : mixed
Return values
mixed —setBubble()
Sets the bubbling behavior.
public
setBubble(bool $bubble) : self
Parameters
- $bubble : bool
-
true means that this handler allows bubbling. false means that bubbling is not permitted.
Return values
self —setFormatter()
Sets the formatter.
public
setFormatter(FormatterInterface $formatter) : self
Parameters
- $formatter : FormatterInterface
Return values
self —setLevel()
Sets minimum logging level at which this handler will be triggered.
public
setLevel(int|string $level) : self
Parameters
- $level : int|string
-
Level or level name
Return values
self —getDefaultFormatter()
Gets the default formatter.
protected
getDefaultFormatter() : FormatterInterface
Return values
FormatterInterface —appendRecord()
private
appendRecord(array<string|int, mixed> $record) : mixed
Parameters
- $record : array<string|int, mixed>
Return values
mixed —collectLogs()
private
collectLogs() : mixed
Return values
mixed —isDuplicate()
private
isDuplicate(array<string|int, mixed> $record) : mixed
Parameters
- $record : array<string|int, mixed>