Пример #1
0
 /**
  * @param   string  $type
  * @throws  \InvalidArgumentException
  * @return  \Zend\Log\Logger
  */
 public function getLogger($type)
 {
     static $serviceTr = array('\\' => '', '_' => ''), $mailServices = array('mail', 'zendlogwritermail');
     $type = (string) $type;
     if (!isset($this->config[$type])) {
         throw new Exception\InvalidArgumentException(sprintf('Type "%s" not registered in config', $type));
     }
     $logger = new Logger();
     if ($this->serviceLocator instanceof ServiceManager) {
         $logger->getWriterPluginManager()->addPeeringServiceManager($this->serviceLocator);
     }
     if (isset($this->config[$type]['writers'])) {
         foreach ($this->config[$type]['writers'] as $name => $config) {
             $name = isset($config['name']) ? (string) $config['name'] : $name;
             $options = isset($config['options']) ? (array) $config['options'] : null;
             $priority = isset($config['priority']) ? (int) $config['priority'] : null;
             if ($this->serviceLocator !== null && in_array(strtr(strtolower($name), $serviceTr), $mailServices)) {
                 $mailService = $this->serviceLocator->get('Zork\\Mail\\Service');
                 if (!isset($options['transport'])) {
                     $options['transport'] = $mailService->getTransport();
                 }
                 if (!isset($options['mail'])) {
                     $options['mail'] = array();
                 }
                 $options['mail'] = $mailService->createMessage($options['mail']);
             }
             $writer = $logger->writerPlugin($name, $options);
             if ($writer instanceof WriterInterface) {
                 if (isset($config['filters'])) {
                     foreach ($config['filters'] as $filterName => $filterConfig) {
                         $filterName = isset($filterConfig['name']) ? (string) $filterConfig['name'] : $filterName;
                         $filterOptions = isset($filterConfig['options']) ? (array) $filterConfig['options'] : null;
                         $filter = $writer->filterPlugin($filterName, $filterOptions);
                         $writer->addFilter($filter, $filterOptions);
                     }
                 }
                 if (isset($config['formatter']['name'])) {
                     $formatter = $writer->formatterPlugin($config['formatter']['name'], isset($config['formatter']['options']) ? $config['formatter']['options'] : array());
                     $writer->setFormatter($formatter);
                 }
             }
             $logger->addWriter($writer, $priority, $options);
         }
     }
     if (isset($this->config[$type]['processors'])) {
         foreach ($this->config[$type]['processors'] as $name => $config) {
             $name = isset($config['name']) ? (string) $config['name'] : $name;
             $options = isset($config['options']) ? (array) $config['options'] : null;
             $priority = isset($config['priority']) ? (int) $config['priority'] : null;
             $logger->addProcessor($name, $priority, $options);
         }
     }
     return $logger;
 }
Пример #2
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config');
     $config = $config['soflomo_log'];
     $logger = new Logger();
     $plugins = $logger->getWriterPluginManager();
     foreach ($config['writers'] as $name => $options) {
         if (!$options['enabled']) {
             continue;
         }
         unset($options['enabled']);
         $writer = $plugins->get($name, $options);
         $logger->addWriter($writer);
     }
     return $logger;
 }