<?php namespace FSProVendor\WPDesk\Logger; use FSProVendor\Monolog\Handler\HandlerInterface; use FSProVendor\Monolog\Logger; use FSProVendor\Monolog\Registry; /** * Manages and facilitates creation of logger * * @package WPDesk\Logger */ class BasicLoggerFactory implements \FSProVendor\WPDesk\Logger\LoggerFactory { /** @var string Last created logger name/channel */ private static $lastLoggerChannel; /** * Creates logger for plugin * * @param string $name The logging channel/name of logger * @param HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc. * @param callable[] $processors Optional array of processors * @return Logger */ public function createLogger($name, $handlers = array(), array $processors = array()) { if (\FSProVendor\Monolog\Registry::hasLogger($name)) { return \FSProVendor\Monolog\Registry::getInstance($name); } self::$lastLoggerChannel = $name; $logger = new \FSProVendor\Monolog\Logger($name, $handlers, $processors); \FSProVendor\Monolog\Registry::addLogger($logger); return $logger; } /** * Returns created Logger by name or last created logger * * @param string $name Name of the logger * * @return Logger */ public function getLogger($name = null) { if ($name === null) { $name = self::$lastLoggerChannel; } return \FSProVendor\Monolog\Registry::getInstance($name); } }