Processor
2 weeks ago
WC
2 weeks ago
WP
2 weeks ago
deprecated
2 weeks ago
BasicLoggerFactory.php
2 weeks ago
LoggerFacade.php
2 weeks ago
LoggerFactory.php
2 weeks ago
Settings.php
2 weeks ago
SimpleLoggerFactory.php
2 weeks ago
WPDeskLoggerFactory.php
2 weeks ago
BasicLoggerFactory.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FSVendor\WPDesk\Logger; |
| 4 | |
| 5 | use FSVendor\Monolog\Handler\HandlerInterface; |
| 6 | use FSVendor\Monolog\Logger; |
| 7 | use FSVendor\Monolog\Registry; |
| 8 | /** |
| 9 | * Manages and facilitates creation of logger |
| 10 | * |
| 11 | * @package WPDesk\Logger |
| 12 | */ |
| 13 | class BasicLoggerFactory implements LoggerFactory |
| 14 | { |
| 15 | /** @var string Last created logger name/channel */ |
| 16 | private static $lastLoggerChannel; |
| 17 | /** |
| 18 | * Creates logger for plugin |
| 19 | * |
| 20 | * @param string $name The logging channel/name of logger |
| 21 | * @param HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc. |
| 22 | * @param callable[] $processors Optional array of processors |
| 23 | * @return Logger |
| 24 | */ |
| 25 | public function createLogger($name, $handlers = array(), array $processors = array()) |
| 26 | { |
| 27 | if (Registry::hasLogger($name)) { |
| 28 | return Registry::getInstance($name); |
| 29 | } |
| 30 | self::$lastLoggerChannel = $name; |
| 31 | $logger = new Logger($name, $handlers, $processors); |
| 32 | Registry::addLogger($logger); |
| 33 | return $logger; |
| 34 | } |
| 35 | /** |
| 36 | * Returns created Logger by name or last created logger |
| 37 | * |
| 38 | * @param string $name Name of the logger |
| 39 | * |
| 40 | * @return Logger |
| 41 | */ |
| 42 | public function getLogger($name = null) |
| 43 | { |
| 44 | if ($name === null) { |
| 45 | $name = self::$lastLoggerChannel; |
| 46 | } |
| 47 | return Registry::getInstance($name); |
| 48 | } |
| 49 | } |
| 50 |