Documentation

LoggerTrait

Hook logging handlers into a class.

Table of Contents

Properties

$loggers  : array<string|int, callable>

Methods

addLogger()  : int
Register a logger.
attach()  : void
Forward any logs from this loggable to a parent loggable.
clearLoggers()  : void
log()  : void
Log something.

Properties

$loggers

private array<string|int, callable> $loggers = []

Methods

addLogger()

Register a logger.

public addLogger(callable|LogSinkInterface $logger[, int|null $level = null ][, string|array<string|int, mixed>|null $category = null ]) : int

Logs can be filtered by level and category.

// Only permit log levels higher than this:
// (excludes INFO, DEBUG, etc)
$loggable->addLogger($logger, Log::LEVEL_WARNING);

// Only permit this category:
$loggable->addLogger($logger, null, 'progress');

// Only permit these categories:
$loggable->addLogger($logger, null, ['log.request', 'log.response']);

// Exclude these categories:
$loggable->addLogger($logger, null, ['stats' => false, 'meta' => false]);
Parameters
$logger : callable|LogSinkInterface

(message, level, category, timestamp)

$level : int|null = null

filter by level

$category : string|array<string|int, mixed>|null = null

filter by category

Return values
int

attach()

Forward any logs from this loggable to a parent loggable.

public attach(callable|LogSinkInterface $logger[, int|null $level = null ][, string|array<string|int, mixed>|null $category = null ]) : void

Use addLogger() instead

Parameters
$logger : callable|LogSinkInterface
$level : int|null = null

filter by level

$category : string|array<string|int, mixed>|null = null

filter by category

log()

Log something.

public log(mixed $message[, int $level = null ][, string|null $category = null ][, float|null $timestamp = null ]) : void
Parameters
$message : mixed
$level : int = null

default: LEVEL_INFO

$category : string|null = null

default: class name (static)

$timestamp : float|null = null

default: now

On this page

Search results