public function convert(Payone_Log4php_LoggerLoggingEvent $event) { $info = $event->getThrowableInformation(); if ($info === null) { return ''; } $ex = $info->getThrowable(); // Format exception to string $strEx = get_class($ex) . ': "' . $ex->getMessage() . '"' . PHP_EOL; $strEx .= 'at ' . $ex->getFile() . ':' . $ex->getLine(); // Add trace if required if ($this->depth === null || $this->depth > 0) { $trace = $ex->getTrace(); foreach ($trace as $key => $item) { if (isset($this->depth) && $key > $this->depth) { break; } $strEx .= PHP_EOL . "#{$key} " . "{$item['file']}:{$item['line']} " . "in {$item['class']}{$item['type']}{$item['function']}()"; } } return $strEx; }
/** * Converts the logging event into an array which can be logged to mongodb. * * @param Payone_Log4php_LoggerLoggingEvent $event * @return array The array representation of the logging event. */ protected function format(Payone_Log4php_LoggerLoggingEvent $event) { $timestampSec = (int) $event->getTimestamp(); $timestampUsec = (int) (($event->getTimestamp() - $timestampSec) * 1000000); $document = array('timestamp' => new MongoDate($timestampSec, $timestampUsec), 'level' => $event->getLevel()->toString(), 'thread' => (int) $event->getThreadName(), 'message' => $event->getMessage(), 'loggerName' => $event->getLoggerName()); $locationInfo = $event->getLocationInformation(); if ($locationInfo != null) { $document['fileName'] = $locationInfo->getFileName(); $document['method'] = $locationInfo->getMethodName(); $document['lineNumber'] = $locationInfo->getLineNumber() == 'NA' ? 'NA' : (int) $locationInfo->getLineNumber(); $document['className'] = $locationInfo->getClassName(); } $throwableInfo = $event->getThrowableInformation(); if ($throwableInfo != null) { $document['exception'] = $this->formatThrowable($throwableInfo->getThrowable()); } return $document; }