\MonologRegistry

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()->addError('Sent to $api Logger instance'); Monolog\Registry::application()->addError('Sent to $application Logger instance'); }

Summary

Methods
Properties
Constants
addLogger()
hasLogger()
removeLogger()
clear()
getInstance()
__callStatic()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$loggers
N/A

Properties

$loggers

$loggers : array<mixed,\Monolog\Logger>

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

Type

array<mixed,\Monolog\Logger>

Methods

addLogger()

addLogger(\Monolog\Logger  $logger, string|null  $name = null, boolean  $overwrite = false) 

Adds new logging channel to the registry

Parameters

\Monolog\Logger $logger

Instance of the logging channel

string|null $name

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

boolean $overwrite

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

Throws

\InvalidArgumentException

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

hasLogger()

hasLogger(string|\Monolog\Logger  $logger) 

Checks if such logging channel exists by name or instance

Parameters

string|\Monolog\Logger $logger

Name or logger instance

removeLogger()

removeLogger(string|\Monolog\Logger  $logger) 

Removes instance from registry by name or instance

Parameters

string|\Monolog\Logger $logger

Name or logger instance

clear()

clear() 

Clears the registry

getInstance()

getInstance(string  $name) : \Monolog\Logger

Gets Logger instance from the registry

Parameters

string $name

Name of the requested Logger instance

Throws

\InvalidArgumentException

If named Logger instance is not in the registry

Returns

\Monolog\Logger

Requested instance of Logger

__callStatic()

__callStatic(string  $name, array  $arguments) : \Monolog\Logger

Gets Logger instance from the registry via static method call

Parameters

string $name

Name of the requested Logger instance

array $arguments

Arguments passed to static method call

Throws

\InvalidArgumentException

If named Logger instance is not in the registry

Returns

\Monolog\Logger

Requested instance of Logger