示例#1
0
 public function testLog()
 {
     $logger = new Collection();
     // Add a logger to the collection
     $subLogger1 = $this->getMockLoggerInterface();
     $subLogger1->expects($this->once())->method('log');
     $logger->add($subLogger1);
     // Add another logger to the collection
     // We will remove it before it gets called
     $subLogger2 = $this->getMockLoggerInterface();
     $subLogger2->expects($this->never())->method('log');
     $logger->add($subLogger2);
     // Add another logger to the collection
     $subLogger3 = $this->getMockLoggerInterface();
     $subLogger3->expects($this->once())->method('log');
     $logger->add($subLogger3);
     // Remove Logger 2 from the collection
     $logger->remove($subLogger2);
     // Perform the log
     $logger->log(LogLevel::ERROR, 'Test Log Message');
 }
示例#2
0
文件: Factory.php 项目: phlib/logger
 /**
  * @param string $name
  * @param array $config
  * @return LoggerType\Collection
  * @throws \DomainException
  */
 public function createCollectionLogger($name, $config)
 {
     $loggerCollection = new LoggerType\Collection();
     foreach ($config['loggers'] as $index => $logger) {
         if (!$logger instanceof LoggerInterface) {
             try {
                 $logger = $this->createLogger($name, $logger);
             } catch (\DomainException $e) {
                 $message = sprintf('%s at index %d', $e->getMessage(), $index);
                 throw new \DomainException($message, null, $e);
             }
         }
         $loggerCollection->add($logger);
     }
     return $loggerCollection;
 }