diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index 087dee2f..60f2ed10 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -107,6 +107,12 @@ class Logger implements LoggerInterface */ protected static $timezone; + /** + * List of all active Logger instances + * @var array of Monolog\Logger + */ + protected static $loggerInstances = array(); + protected $name; /** @@ -125,6 +131,31 @@ class Logger implements LoggerInterface */ protected $processors; + /** + * Registers new Logger instance + * @param string $name The logging channel name + * @param Monolog\Logger $instance Instance to register + */ + public static function registerLogger($name, Logger $instance) + { + self::$loggerInstances[$name] = $instance; + } + + /** + * Gets instance of requested logging channel + * @param string $name The logging channel name + * @return Monolog\Logger + * @throws InvalidArgumentException If logging channel has not been created + */ + public static function __callStatic($name) + { + if(!isset(self::$loggerInstances[$name])) { + throw new \InvalidArgumentException('The requested logging channel has not been created yet'); + } + + return self::$loggerInstances[$name]; + } + /** * @param string $name The logging channel * @param array $handlers Optional stack of handlers, the first one in the array is called first, etc. @@ -135,6 +166,7 @@ class Logger implements LoggerInterface $this->name = $name; $this->handlers = $handlers; $this->processors = $processors; + self::registerLogger($this->name, $this); } /**