Example #1
0
 /**
  * @param HandlerInterface $handler
  * @param bool $flush
  */
 public function sendToHandler($handler, $flush = false)
 {
     $handler->handleBatch($this->buffer);
     if ($flush) {
         $this->flush();
     }
 }
Example #2
0
 /**
  * @internal
  */
 public static function includeStacktraces(HandlerInterface $handler)
 {
     $formatter = $handler->getFormatter();
     if ($formatter instanceof LineFormatter || $formatter instanceof JsonFormatter) {
         $formatter->includeStacktraces();
     }
 }
 private function addFormatter(HandlerInterface $handler, MonologHandlerOptions $options)
 {
     if ($formatterOptions = $options->getFormatter()) {
         $formatterFactory = new MonologFormatterFactory();
         $formatter = $formatterFactory->createFormatter($formatterOptions);
         $handler->setFormatter($formatter);
     }
 }
 /**
  * Sets formatter and processors.
  *
  * @param HandlerInterface $handler
  * @return HandlerInterface
  */
 protected function initHandler(HandlerInterface $handler)
 {
     if ($this->formatter != null) {
         $handler->setFormatter($this->formatter);
     }
     foreach ($this->processors as $processor) {
         $handler->pushProcessor($processor);
     }
     return $handler;
 }
 /**
  * @param Logger $Logger Logger to configure
  * @param HandlerInterface $AbstractHandler Handler to configure
  * @param array $config formatter configuration
  *
  * @throws FormatterClassMissingException
  * @throws SectionArgsMissingException
  */
 protected function configureFormatter(Logger $Logger, HandlerInterface $AbstractHandler, array $config)
 {
     if (!isset($config[Config::FORMATTER_CLASS])) {
         throw new FormatterClassMissingException('Formatter class is missing for [' . $Logger->getName() . '] log');
     }
     if (!isset($config[Config::FORMATTER_ARGS])) {
         throw new SectionArgsMissingException('Section args is missing for formatter [' . $Logger->getName() . '] log');
     }
     $Reflector = new ReflectionClass($config[Config::FORMATTER_CLASS]);
     /** @var FormatterInterface $AbstractFormatter */
     $AbstractFormatter = $Reflector->newInstanceArgs($config[Config::FORMATTER_ARGS]);
     $AbstractHandler->setFormatter($AbstractFormatter);
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function getFormatter() : FormatterInterface
 {
     if ($this->handler instanceof FormattableHandlerInterface) {
         return $this->handler->getFormatter($formatter);
     }
     throw new \LogicException('The wrapped handler does not implement ' . FormattableHandlerInterface::class);
 }
 /**
  * @param HandlerInterface $handler
  */
 public function injectProcessors($handler)
 {
     if (!empty($this->creationOptions['tags'])) {
         $tagProcessor = new TagProcessor($this->creationOptions['tags']);
         $handler->pushProcessor($tagProcessor);
     }
     if (empty($this->creationOptions['processors'])) {
         return;
     }
     foreach ($this->creationOptions['processors'] as $processor) {
         if (is_string($processor)) {
             /** @var callable $processor */
             $processor = $this->getServiceLocator()->get("monolog.processor.{$processor}");
         }
         $handler->pushProcessor($processor);
     }
 }
 /**
  *
  * {@inheritdoc}
  *
  */
 public function handleBatch(array $records)
 {
     $filtered = array();
     foreach ($records as $record) {
         if ($this->isHandling($record)) {
             $filtered[] = $record;
         }
     }
     $this->handler->handleBatch($filtered);
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function getFormatter()
 {
     return $this->handler->getFormatter();
 }
 public function setLevel($level)
 {
     $this->cloudFoundryHandler->setLevel($level);
 }
Example #11
0
 /**
  * Parse Processor.
  *
  * @param \Monolog\Handler\HandlerInterface $handler
  * @param array|object|null                 $processors
  *
  * @return \Monolog\Handler\HandlerInterface
  */
 protected function parseProcessor(HandlerInterface $handler, $processors = null) : HandlerInterface
 {
     if ($processors === null) {
         return $handler;
     }
     if (is_array($processors)) {
         foreach ($processors as $processor => $settings) {
             $handler->pushProcessor(new $processor($settings));
         }
     } elseif (is_object($processors)) {
         $handler->pushProcessor($processors);
     }
     return $handler;
 }
Example #12
0
 /**
  * @override
  * @inheritDoc
  */
 public function getFormatter()
 {
     return $this->model->getFormatter();
 }
Example #13
0
 public function getFormatter()
 {
     return $this->delegate->getFormatter();
 }
Example #14
0
 private function setProcessorsToHandlerFromConfig(array $processors, HandlerInterface $handlerInstance)
 {
     foreach ($processors as $processor) {
         if (is_array($processor)) {
             $class = $processor['class'];
             $args = $processor['args'];
         } else {
             $class = $processor;
             $args = [];
         }
         $reflectionClass = new ReflectionClass($class);
         $processorInstance = $reflectionClass->newInstanceArgs($args);
         $handlerInstance->pushProcessor($processorInstance);
     }
 }