Typecast
in package
implements
LogSourceInterface
uses
LoggerTrait
Typecasting for objects.
This does scalar-to-scalar casts and will apply the Cast attribute, if present.
Tags
Table of Contents
Interfaces
- LogSourceInterface
- This class can emit logs.
Properties
Methods
- __construct() : void
- addLogger() : int
- Register a logger.
- attach() : void
- Forward any logs from this loggable to a parent loggable.
- cast() : bool
- Cast a value for this object.
- clearLoggers() : void
- log() : void
- Log something.
Properties
$target
public
object
$target
$loggers
private
array<string|int, callable>
$loggers
= []
Methods
__construct()
public
__construct(object $target) : void
Parameters
- $target : object
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
intattach()
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
cast()
Cast a value for this object.
public
cast(string $field, mixed &$value) : bool
- between applicable scalar types
- properties that have Cast attributes
Parameters
- $field : string
- $value : mixed
-
mutable
Return values
bool —true if the type matches, false otherwise
clearLoggers()
public
clearLoggers() : void
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