Documentation

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
author

Jordi Boggiano j.boggiano@seld.be

phpstan-import-type

Record from \Monolog\Logger

phpstan-import-type

Level from \Monolog\Logger

phpstan-import-type

LevelName from \Monolog\Logger

Interfaces, Classes and Traits

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

Table of Contents

$activationStrategy  : ActivationStrategyInterface
$bubble  : bool
$buffer  : array<string|int, Record>
$buffering  : bool
$bufferSize  : int
$handler  : callable|HandlerInterface
$passthruLevel  : int|null
$processors  : array<string|int, callable>
$stopBuffering  : bool
__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
{@inheritDoc}
handleBatch()  : void
Handles a set of records at once.
isHandling()  : bool
{@inheritDoc}
popProcessor()  : callable
{@inheritDoc}
pushProcessor()  : HandlerInterface
{@inheritDoc}
reset()  : void
setFormatter()  : HandlerInterface
Sets the formatter.
processRecord()  : array<string|int, mixed>
Processes a record.
resetProcessors()  : void
flushBuffer()  : void
Resets the state of the handler. Stops forwarding records to the wrapped handler.

Properties

$processors

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

array<ProcessorInterface|callable(Record): Record>

Methods

__construct()

public __construct(callable|HandlerInterface $handler[, int|string|ActivationStrategyInterface $activationStrategy = null ], int $bufferSize[, bool $bubble = true ][, bool $stopBuffering = true ][, int|string $passthruLevel = null ]) : mixed
Parameters
$handler : callable|HandlerInterface

Handler or factory callable($record|null, $fingersCrossedHandler).

$activationStrategy : int|string|ActivationStrategyInterface = null

Strategy which determines when this handler takes action, or a level name/value at which the handler is activated

$bufferSize : int

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 = null

Minimum level to always flush to handler on close, even if strategy not triggered

Tags
psalm-param

HandlerInterface|callable(?Record, HandlerInterface): HandlerInterface $handler

phpstan-param

Level|LevelName|LogLevel::* $passthruLevel

phpstan-param

Level|LevelName|LogLevel::*|ActivationStrategyInterface $activationStrategy

Return values
mixed

__destruct()

public __destruct() : mixed
Return values
mixed

__sleep()

public __sleep() : mixed
Return values
mixed

activate()

Manually activate this logger regardless of the activation strategy

public activate() : void
Return values
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.

Return values
void

getHandler()

Return the nested handler

public getHandler([array<string|int, mixed>|null $record = null ]) : HandlerInterface

If the handler was provided as a factory callable, this will trigger the handler's instantiation.

Parameters
$record : array<string|int, mixed>|null = null
Tags
phpstan-param

Record $record

Return values
HandlerInterface

handle()

{@inheritDoc}

public handle(array<string|int, mixed> $record) : bool
Parameters
$record : array<string|int, mixed>
Return values
bool

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 (an array of record arrays)

Return values
void

isHandling()

{@inheritDoc}

public isHandling(array<string|int, mixed> $record) : bool
Parameters
$record : array<string|int, mixed>
Return values
bool

processRecord()

Processes a record.

protected processRecord(array<string|int, mixed> $record) : array<string|int, mixed>
Parameters
$record : array<string|int, mixed>
Tags
phpstan-param

Record $record

phpstan-return

Record

Return values
array<string|int, mixed>

flushBuffer()

Resets the state of the handler. Stops forwarding records to the wrapped handler.

private flushBuffer() : void
Return values
void

Search results