示例#1
0
 public function testDefFormatWithPreviousException()
 {
     $formatter = new JsonFormatter();
     $exception = new \RuntimeException('Foo', 0, new \LogicException('Wut?'));
     $formattedPrevException = $this->formatException($exception->getPrevious());
     $formattedException = $this->formatException($exception, $formattedPrevException);
     $message = $this->formatRecordWithExceptionInContext($formatter, $exception);
     $this->assertContextContainsFormattedException($formattedException, $message);
 }
示例#2
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);
 }
示例#3
0
 public static function logException($exception)
 {
     if (is_string($exception)) {
         $exception = new \RuntimeException($exception);
     }
     if (self::$error === true || !self::$currentRootSpan || !$exception instanceof \Exception) {
         return;
     }
     // We are only interested in the original exception
     while ($previous = $exception->getPrevious()) {
         $exception = $previous;
     }
     self::$error = true;
     self::$currentRootSpan->annotate(array("err_msg" => $exception->getMessage(), "err_source" => $exception->getFile() . ':' . $exception->getLine(), "err_exception" => get_class($exception), "err_trace" => \Tideways\Profiler\BacktraceConverter::convertToString($exception->getTrace())));
 }