コード例 #1
0
 /**
  * подготовить запись в лог
  *
  * @param int    $channelId
  * @param string $channelName
  * @param int    $transferId
  * @param string $requestAction
  * @param string $requestText
  * @param string $responseStatus
  * @param        $responseText
  * @param        $errorCode
  * @param        $responseError
  * @param int    $requestTime
  * @param int    $responseTime
  */
 public function prepare($channelId, $channelName, $transferId, $requestAction, $requestText, $responseStatus, $responseText, $errorCode, $responseError, $requestTime, $responseTime)
 {
     $attributes = array('channel_id' => $channelId, 'transfer_id' => $transferId, 'channel_name' => $channelName, 'request_action' => $requestAction, 'request_text' => $requestText, 'response_status' => $responseStatus, 'response_text' => $responseText, 'error_code' => $errorCode, 'response_error' => $responseError, 'dt_request' => PaymentChannelAbstract::timetostr($requestTime), 'dt_response' => PaymentChannelAbstract::timetostr($responseTime));
     $jsonFormatter = new JsonFormatter();
     $this->message = $jsonFormatter->format($attributes);
     $this->requestAction = $requestAction;
     $this->transfer_id = $transferId;
 }
コード例 #2
0
 /**
  * @covers Monolog\Formatter\JsonFormatter::format
  */
 public function testFormat()
 {
     $formatter = new JsonFormatter();
     $record = $this->getRecord();
     $this->assertEquals(json_encode($record) . "\n", $formatter->format($record));
     $formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_JSON, false);
     $record = $this->getRecord();
     $this->assertEquals(json_encode($record), $formatter->format($record));
 }
コード例 #3
0
ファイル: JsonFormatterTest.php プロジェクト: jorjoh/Varden
 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);
 }
コード例 #4
0
 public function format(array $record)
 {
     // extract format and extra fields from the record
     $format = $record["channel"];
     unset($record["channel"]);
     $extra = $record["extra"];
     unset($record["extra"]);
     // merge the record and extra arrays
     $record = array_replace($record, $extra);
     // add a timestamp field if we don;t have one
     if (!isset($record["timestamp"]) && !empty($record["datetime"])) {
         /** @var \DateTime $dateTime */
         $dateTime = $record["datetime"];
         $record["timestamp"] = $dateTime->getTimestamp();
     }
     return parent::format(["format" => $format, "entry" => $record]);
 }
コード例 #5
0
 /**
  * @covers Monolog\Formatter\JsonFormatter::format
  */
 public function testFormat()
 {
     $formatter = new JsonFormatter();
     $record = $this->getRecord();
     $this->assertEquals(json_encode($record), $formatter->format($record));
 }
コード例 #6
0
 /**
  * @param array $record
  * @return string formatted record
  */
 public function format(array $record)
 {
     $entry = ['@timestamp' => self::now(), '@message' => $record['message'], '@context' => (object) $record['context'], '@fields' => (object) $record['extra'], 'severity' => strtolower($record['level_name']), 'program' => $record['channel'], '@source_host' => gethostname()];
     return parent::format($entry);
 }
コード例 #7
0
 public function format(array $record)
 {
     return parent::format($this->mapRecord($record));
 }
コード例 #8
0
ファイル: JsonFormatterTest.php プロジェクト: naldz/cyberden
 /**
  * @param JsonFormatter $formatter
  * @param \Exception|\Throwable $exception
  *
  * @return string
  */
 private function formatRecordWithExceptionInContext(JsonFormatter $formatter, $exception)
 {
     $message = $formatter->format(array('level_name' => 'CRITICAL', 'channel' => 'core', 'context' => array('exception' => $exception), 'datetime' => null, 'extra' => array(), 'message' => 'foobar'));
     return $message;
 }
コード例 #9
0
 public function testFormat()
 {
     $formatter = new JsonFormatter();
     $record = $formatter->format($msg = array('level_name' => 'WARNING', 'channel' => 'log', 'message' => array('foo'), 'datetime' => new \DateTime(), 'extra' => array()));
     $this->assertEquals(json_encode($msg), $record['message']);
 }
コード例 #10
0
 public function format(array $record)
 {
     return parent::format(el_format_record($record));
 }