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
Properties
- $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
Methods
- __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() : bool
- Handles a record.
- 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
= \Monolog\Logger::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
__destruct()
public
__destruct() : mixed
clear()
Clears the buffer without flushing any messages down to the wrapped handler.
public
clear() : mixed
close()
Closes the handler.
public
close() : mixed
flush()
public
flush() : 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
FormatterInterfacegetLevel()
Gets minimum logging level at which this handler will be triggered.
public
getLevel() : int
Return values
inthandle()
Handles a record.
public
handle(array<string|int, mixed> $record) : bool
Parameters
- $record : array<string|int, mixed>
-
The record to handle
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) : mixed
Parameters
- $records : array<string|int, mixed>
-
The records to handle (an array of record arrays)
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
boolpopProcessor()
Removes the processor on top of the stack and returns it.
public
popProcessor() : callable
Return values
callablepushProcessor()
Adds a processor in the stack.
public
pushProcessor(mixed $callback) : self
Parameters
- $callback : mixed
Return values
selfreset()
public
reset() : 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
selfsetFormatter()
Sets the formatter.
public
setFormatter(FormatterInterface $formatter) : self
Parameters
- $formatter : FormatterInterface
Return values
selfsetLevel()
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
selfgetDefaultFormatter()
Gets the default formatter.
protected
getDefaultFormatter() : FormatterInterface
Return values
FormatterInterfaceappendRecord()
private
appendRecord(array<string|int, mixed> $record) : mixed
Parameters
- $record : array<string|int, mixed>
collectLogs()
private
collectLogs() : mixed
isDuplicate()
private
isDuplicate(array<string|int, mixed> $record) : mixed
Parameters
- $record : array<string|int, mixed>