ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Monolog\Registry Class Reference

Monolog log registry. More...

+ Collaboration diagram for Monolog\Registry:

Static Public Member Functions

static addLogger (Logger $logger, $name=null, $overwrite=false)
 Adds new logging channel to the registry. More...
 
static hasLogger ($logger)
 Checks if such logging channel exists by name or instance. More...
 
static removeLogger ($logger)
 Removes instance from registry by name or instance. More...
 
static clear ()
 Clears the registry. More...
 
static getInstance ($name)
 Gets Logger instance from the registry. More...
 
static __callStatic ($name, $arguments)
 Gets Logger instance from the registry via static method call. More...
 

Static Private Attributes

static $loggers = array()
 

Detailed Description

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'); }

Author
Tomas Tatarko tomas.nosp@m.@tat.nosp@m.arko..nosp@m.sk

Definition at line 38 of file Registry.php.

Member Function Documentation

◆ __callStatic()

static Monolog\Registry::__callStatic (   $name,
  $arguments 
)
static

Gets Logger instance from the registry via static method call.

Parameters
string$nameName of the requested Logger instance
array$argumentsArguments passed to static method call
Returns
Logger Requested instance of Logger
Exceptions

InvalidArgumentException If named Logger instance is not in the registry

Definition at line 130 of file Registry.php.

131 {
132 return self::getInstance($name);
133 }
static getInstance($name)
Gets Logger instance from the registry.
Definition: Registry.php:113

◆ addLogger()

static Monolog\Registry::addLogger ( Logger  $logger,
  $name = null,
  $overwrite = false 
)
static

Adds new logging channel to the registry.

Parameters
Logger$loggerInstance of the logging channel
string | null$nameName of the logging channel ($logger->getName() by default)
boolean$overwriteOverwrite instance in the registry if the given name already exists?
Exceptions

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

Definition at line 55 of file Registry.php.

56 {
57 $name = $name ?: $logger->getName();
58
59 if (isset(self::$loggers[$name]) && !$overwrite) {
60 throw new InvalidArgumentException('Logger with the given name already exists');
61 }
62
63 self::$loggers[$name] = $logger;
64 }

References Monolog\Logger\getName().

+ Here is the call graph for this function:

◆ clear()

static Monolog\Registry::clear ( )
static

Clears the registry.

Definition at line 101 of file Registry.php.

102 {
103 self::$loggers = array();
104 }

◆ getInstance()

static Monolog\Registry::getInstance (   $name)
static

Gets Logger instance from the registry.

Parameters
string$nameName of the requested Logger instance
Returns
Logger Requested instance of Logger
Exceptions

InvalidArgumentException If named Logger instance is not in the registry

Definition at line 113 of file Registry.php.

114 {
115 if (!isset(self::$loggers[$name])) {
116 throw new InvalidArgumentException(sprintf('Requested "%s" logger instance is not in the registry', $name));
117 }
118
119 return self::$loggers[$name];
120 }

◆ hasLogger()

static Monolog\Registry::hasLogger (   $logger)
static

Checks if such logging channel exists by name or instance.

Parameters
string | Logger$loggerName or logger instance

Definition at line 71 of file Registry.php.

72 {
73 if ($logger instanceof Logger) {
74 $index = array_search($logger, self::$loggers, true);
75
76 return false !== $index;
77 } else {
78 return isset(self::$loggers[$logger]);
79 }
80 }

◆ removeLogger()

static Monolog\Registry::removeLogger (   $logger)
static

Removes instance from registry by name or instance.

Parameters
string | Logger$loggerName or logger instance

Definition at line 87 of file Registry.php.

88 {
89 if ($logger instanceof Logger) {
90 if (false !== ($idx = array_search($logger, self::$loggers, true))) {
91 unset(self::$loggers[$idx]);
92 }
93 } else {
94 unset(self::$loggers[$logger]);
95 }
96 }

Field Documentation

◆ $loggers

Monolog\Registry::$loggers = array()
staticprivate

Definition at line 45 of file Registry.php.


The documentation for this class was generated from the following file: