Exemplo n.º 1
0
 public function testDefFormatWithPreviousException()
 {
     $formatter = new JsonFormatter();
     $exception = new \RuntimeException('Foo', 0, new \LogicException('Wut?'));
     $message = $formatter->format(array('level_name' => 'CRITICAL', 'channel' => 'core', 'context' => array('exception' => $exception), 'datetime' => new \DateTime(), 'extra' => array(), 'message' => 'foobar'));
     if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
         $pathPrevious = substr(json_encode($exception->getPrevious()->getFile(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 1, -1);
         $pathException = substr(json_encode($exception->getFile(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 1, -1);
     } else {
         $pathPrevious = substr(json_encode($exception->getPrevious()->getFile()), 1, -1);
         $pathException = substr(json_encode($exception->getFile()), 1, -1);
     }
     $this->assertEquals('{"level_name":"CRITICAL","channel":"core","context":{"exception":{"class":"RuntimeException","message":"' . $exception->getMessage() . '","code":' . $exception->getCode() . ',"file":"' . $pathException . ':' . $exception->getLine() . '","previous":{"class":"LogicException","message":"' . $exception->getPrevious()->getMessage() . '","code":' . $exception->getPrevious()->getCode() . ',"file":"' . $pathPrevious . ':' . $exception->getPrevious()->getLine() . '"}}},"datetime":' . json_encode(new \DateTime()) . ',"extra":[],"message":"foobar"}' . "\n", $message);
 }
Exemplo n.º 2
0
 /**
  * @param \Zend\Mvc\MvcEvent $oEvent
  * @return \BoilerAppLogger\Logger\MvcLogger
  */
 public function logError(\Zend\Mvc\MvcEvent $oEvent)
 {
     //Create log error
     $oLogError = new \BoilerAppLogger\Entity\LogErrorEntity();
     if (!($oException = $oEvent->getParam('exception')) instanceof \Exception) {
         if (!($oResponse = $oEvent->getResponse()) instanceof \Zend\Http\Response) {
             throw new \LogicException(sprintf('Response expects an instance of \\Zend\\Http\\Response, "%s" given', is_object($oResponse) ? get_class($oResponse) : gettype($oResponse)));
         }
         $oException = new \RuntimeException($oEvent->getError(), $oResponse->getStatusCode());
     } else {
         $oLogError->setLogErrorFile($oException->getFile())->setLogErrorLine($oException->getLine());
     }
     $this->getLogErrorRepository()->create($oLogError->setLogErrorMessage($oException->getMessage())->setLogErrorCode($oException->getCode())->setLogErrorTrace($oException->getTraceAsString())->setLogErrorLog($this->getCurrentLog()));
     return $this;
 }