ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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('application'); $api = new Monolog('api');

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

function testLogger() { Monolog::api()->addError('Sent to $api Logger instance'); Monolog::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
Exceptions

Definition at line 130 of file Registry.php.

References $name.

131  {
132  return self::getInstance($name);
133  }

◆ 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)
bool$overwriteOverwrite instance in the registry if the given name already exists?
Exceptions

Definition at line 55 of file Registry.php.

References $name, and Monolog\Logger\getName().

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  }
+ 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
Exceptions

Definition at line 113 of file Registry.php.

References $name.

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.

References $index.

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  }
$index
Definition: metadata.php:60

◆ 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: