Documentation

SamplingHandler extends AbstractHandler
in package
implements ProcessableHandlerInterface, FormattableHandlerInterface Uses ProcessableHandlerTrait

Sampling handler

A sampled event stream can be useful for logging high frequency events in a production environment where you only need an idea of what is happening and are not concerned with capturing every occurrence. Since the decision to handle or not handle a particular event is determined randomly, the resulting sampled log is not guaranteed to contain 1/N of the events that occurred in the application, but based on the Law of large numbers, it will tend to be close to this ratio with a large number of attempts.

Tags
author

Bryan Davis bd808@wikimedia.org

author

Kunal Mehta legoktm@gmail.com

phpstan-import-type

Record from \Monolog\Logger

phpstan-import-type

Level from \Monolog\Logger

Interfaces, Classes and Traits

ProcessableHandlerInterface
Interface to describe loggers that have processors
FormattableHandlerInterface
Interface to describe loggers that have a formatter

Table of Contents

$bubble  : bool
$factor  : int
$handler  : HandlerInterface|callable
$level  : int
$processors  : array<string|int, callable>
__construct()  : mixed
__destruct()  : mixed
__sleep()  : mixed
close()  : void
Closes the handler.
getBubble()  : bool
Gets the bubbling behavior.
getFormatter()  : FormatterInterface
Gets the formatter.
getHandler()  : HandlerInterface
Return the nested handler
getLevel()  : int
Gets minimum logging level at which this handler will be triggered.
handle()  : bool
handleBatch()  : void
Handles a set of records at once.
isHandling()  : bool
{@inheritDoc}
popProcessor()  : callable
{@inheritDoc}
pushProcessor()  : HandlerInterface
{@inheritDoc}
reset()  : void
setBubble()  : self
Sets the bubbling behavior.
setFormatter()  : HandlerInterface
Sets the formatter.
setLevel()  : self
Sets minimum logging level at which this handler will be triggered.
processRecord()  : array<string|int, mixed>
Processes a record.
resetProcessors()  : void

Properties

$handler

protected HandlerInterface|callable $handler
Tags
phpstan-var

HandlerInterface|callable(Record|array{level: Level}|null, HandlerInterface): HandlerInterface

$level

protected int $level = MonologLogger::DEBUG
Tags
phpstan-var

Level

$processors

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

array<ProcessorInterface|callable(Record): Record>

Methods

__construct()

public __construct(callable|HandlerInterface $handler, int $factor) : mixed
Parameters
$handler : callable|HandlerInterface

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

$factor : int

Sample factor (e.g. 10 means every ~10th record is sampled)

Tags
psalm-param

HandlerInterface|callable(Record|array{level: Level}|null, HandlerInterface): HandlerInterface $handler

Return values
mixed

__destruct()

public __destruct() : mixed
Return values
mixed

__sleep()

public __sleep() : mixed
Return values
mixed

close()

Closes the handler.

public close() : void
Return values
void

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.

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|array{level: Level}|null $record

Return values
HandlerInterface

getLevel()

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

public getLevel() : int
Tags
phpstan-return

Level

Return values
int

handle()

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

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

setLevel()

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

public setLevel(Level|LevelName|\Psr\Log\LogLevel::* $level) : self
Parameters
$level : Level|LevelName|\Psr\Log\LogLevel::*

Level or level name

Return values
self

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>

Search results