FingersCrossedHandler
extends Handler
in package
implements
ProcessableHandlerInterface, ResettableInterface, FormattableHandlerInterface
uses
ProcessableHandlerTrait
Buffers all records until a certain level is reached
The advantage of this approach is that you don't get any clutter in your log files. Only requests which actually trigger an error (or whatever your actionLevel is) will be in the logs, but they will contain all records, not only those above the level threshold.
You can then have a passthruLevel as well which means that at the end of the request, even if it did not get activated, it will still send through log records of e.g. at least a warning level.
You can find the various activation strategies in the Monolog\Handler\FingersCrossed\ namespace.
Tags
Table of Contents
Interfaces
- ProcessableHandlerInterface
- Interface to describe loggers that have processors
- ResettableInterface
- Handler or Processor implementing this interface will be reset when Logger::reset() is called.
- FormattableHandlerInterface
- Interface to describe loggers that have a formatter
Properties
- $activationStrategy : ActivationStrategyInterface
- $bubble : bool
- $buffer : array<string|int, LogRecord>
- $buffering : bool
- $bufferSize : int
- $handler : Closure|HandlerInterface
- Handler or factory Closure($record, $this)
- $passthruLevel : Level|null
- $processors : array<string|int, callable>
- $stopBuffering : bool
Methods
- __construct() : mixed
- __destruct() : mixed
- __sleep() : mixed
- activate() : void
- Manually activate this logger regardless of the activation strategy
- clear() : void
- Clears the buffer without flushing any messages down to the wrapped handler.
- close() : void
- Closes the handler.
- getFormatter() : FormatterInterface
- Gets the formatter.
- getHandler() : HandlerInterface
- Return the nested handler
- 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
- setFormatter() : HandlerInterface
- Sets the formatter.
- processRecord() : LogRecord
- resetProcessors() : void
- flushBuffer() : void
- Resets the state of the handler. Stops forwarding records to the wrapped handler.
Properties
$activationStrategy
protected
ActivationStrategyInterface
$activationStrategy
$bubble
protected
bool
$bubble
$buffer
protected
array<string|int, LogRecord>
$buffer
= []
$buffering
protected
bool
$buffering
= true
$bufferSize
protected
int
$bufferSize
$handler
Handler or factory Closure($record, $this)
protected
Closure|HandlerInterface
$handler
Tags
$passthruLevel
protected
Level|null
$passthruLevel
= null
$processors
protected
array<string|int, callable>
$processors
= []
Tags
$stopBuffering
protected
bool
$stopBuffering
Methods
__construct()
public
__construct(Closure|HandlerInterface $handler[, int|string|Level|LogLevel::* $activationStrategy = null ][, int $bufferSize = 0 ][, bool $bubble = true ][, bool $stopBuffering = true ][, int|string|Level|LogLevel::*|null $passthruLevel = null ]) : mixed
Parameters
- $handler : Closure|HandlerInterface
-
Handler or factory Closure($record|null, $fingersCrossedHandler).
- $activationStrategy : int|string|Level|LogLevel::* = null
-
Strategy which determines when this handler takes action, or a level name/value at which the handler is activated
- $bufferSize : int = 0
-
How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
- $bubble : bool = true
-
Whether the messages that are handled can bubble up the stack or not
- $stopBuffering : bool = true
-
Whether the handler should stop buffering after being triggered (default true)
- $passthruLevel : int|string|Level|LogLevel::*|null = null
-
Minimum level to always flush to handler on close, even if strategy not triggered
Tags
__destruct()
public
__destruct() : mixed
__sleep()
public
__sleep() : mixed
activate()
Manually activate this logger regardless of the activation strategy
public
activate() : void
clear()
Clears the buffer without flushing any messages down to the wrapped handler.
public
clear() : void
It also resets the handler to its initial buffering state.
close()
Closes the handler.
public
close() : void
Tags
getFormatter()
Gets the formatter.
public
getFormatter() : FormatterInterface
Tags
Return values
FormatterInterfacegetHandler()
Return the nested handler
public
getHandler([LogRecord|null $record = null ]) : HandlerInterface
If the handler was provided as a factory, this will trigger the handler's instantiation.
Parameters
- $record : LogRecord|null = null
Return values
HandlerInterfacehandle()
Handles a record.
public
handle(LogRecord $record) : bool
Parameters
- $record : LogRecord
-
The record to handle
Tags
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
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
Return values
boolpopProcessor()
public
popProcessor() : callable
Tags
Return values
callablepushProcessor()
public
pushProcessor(callable $callback) : HandlerInterface
Parameters
- $callback : callable
Tags
Return values
HandlerInterfacereset()
public
reset() : void
setFormatter()
Sets the formatter.
public
setFormatter(FormatterInterface $formatter) : HandlerInterface
Parameters
- $formatter : FormatterInterface
Tags
Return values
HandlerInterface —self
processRecord()
protected
processRecord(LogRecord $record) : LogRecord
Parameters
- $record : LogRecord
Return values
LogRecordresetProcessors()
protected
resetProcessors() : void
flushBuffer()
Resets the state of the handler. Stops forwarding records to the wrapped handler.
private
flushBuffer() : void