Documentation

Registry
in package

Monolog log registry

Allows to get Logger instances in the global scope via static method calls on this class.

$application = new Monolog\Logger('application'); $api = new Monolog\Logger('api');

Monolog\Registry::addLogger($application); Monolog\Registry::addLogger($api);

function testLogger() { Monolog\Registry::api()->error('Sent to $api Logger instance'); Monolog\Registry::application()->error('Sent to $application Logger instance'); }

Tags
author

Tomas Tatarko tomas@tatarko.sk

Table of Contents

$loggers  : array<string|int, Logger>
List of all loggers in the registry (by named indexes)
__callStatic()  : Logger
Gets Logger instance from the registry via static method call
addLogger()  : void
Adds new logging channel to the registry
clear()  : void
Clears the registry
getInstance()  : Logger
Gets Logger instance from the registry
hasLogger()  : bool
Checks if such logging channel exists by name or instance
removeLogger()  : void
Removes instance from registry by name or instance

Properties

$loggers

List of all loggers in the registry (by named indexes)

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

Methods

__callStatic()

Gets Logger instance from the registry via static method call

public static __callStatic(string $name, array<string|int, mixed> $arguments) : Logger
Parameters
$name : string

Name of the requested Logger instance

$arguments : array<string|int, mixed>

Arguments passed to static method call

Tags
throws
InvalidArgumentException

If named Logger instance is not in the registry

Return values
Logger

Requested instance of Logger

addLogger()

Adds new logging channel to the registry

public static addLogger(Logger $logger[, string|null $name = null ][, bool $overwrite = false ]) : void
Parameters
$logger : Logger

Instance of the logging channel

$name : string|null = null

Name of the logging channel ($logger->getName() by default)

$overwrite : bool = false

Overwrite instance in the registry if the given name already exists?

Tags
throws
InvalidArgumentException

If $overwrite set to false and named Logger instance already exists

Return values
void

clear()

Clears the registry

public static clear() : void
Return values
void

getInstance()

Gets Logger instance from the registry

public static getInstance(string $name) : Logger
Parameters
$name : string

Name of the requested Logger instance

Tags
throws
InvalidArgumentException

If named Logger instance is not in the registry

Return values
Logger

hasLogger()

Checks if such logging channel exists by name or instance

public static hasLogger(string|Logger $logger) : bool
Parameters
$logger : string|Logger

Name or logger instance

Return values
bool

removeLogger()

Removes instance from registry by name or instance

public static removeLogger(string|Logger $logger) : void
Parameters
$logger : string|Logger

Name or logger instance

Return values
void

Search results