LogLevel::EMERGENCY, Logger::ALERT => LogLevel::ALERT, Logger::CRIT => LogLevel::CRITICAL, Logger::ERR => LogLevel::ERROR, Logger::WARN => LogLevel::WARNING, Logger::NOTICE => LogLevel::NOTICE, Logger::INFO => LogLevel::INFO, Logger::DEBUG => LogLevel::DEBUG, ]; /** * Default log level (warning) * * @var int */ protected $defaultLogLevel = LogLevel::WARNING; /** * Constructor * * Set options for a writer. Accepted options are: * * - filters: array of filters to add to this filter * - formatter: formatter for this writer * - logger: PsrLoggerInterface implementation * * @param array|Traversable|PsrLoggerInterface $options * @throws Exception\InvalidArgumentException */ public function __construct($options = null) { if ($options instanceof PsrLoggerInterface) { $this->setLogger($options); } if ($options instanceof Traversable) { $options = iterator_to_array($options); } if (is_array($options) && isset($options['logger'])) { $this->setLogger($options['logger']); } parent::__construct($options); if (null === $this->logger) { $this->setLogger(new NullLogger()); } } /** * Write a message to the PSR-3 compliant logger. * * @param array $event event data * @return void */ protected function doWrite(array $event) { $priority = $event['priority']; $message = $event['message']; $context = $event['extra']; $level = $this->psrPriorityMap[$priority] ?? $this->defaultLogLevel; $this->logger->log($level, $message, $context); } }