Ejemplo n.º 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;
 }
 /**
  * @covers Monolog\Formatter\JsonFormatter::formatBatch
  * @covers Monolog\Formatter\JsonFormatter::formatBatchNewlines
  */
 public function testFormatBatchNewlines()
 {
     $formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_NEWLINES);
     $records = $expected = array($this->getRecord(Logger::WARNING), $this->getRecord(Logger::DEBUG));
     array_walk($expected, function (&$value, $key) {
         $value = json_encode($value);
     });
     $this->assertEquals(implode("\n", $expected), $formatter->formatBatch($records));
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 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]);
 }
 /**
  * @covers Monolog\Formatter\JsonFormatter::formatBatch
  */
 public function testFormatBatch()
 {
     $formatter = new JsonFormatter();
     $records = array($this->getRecord(Logger::WARNING), $this->getRecord(Logger::DEBUG));
     $this->assertEquals(json_encode($records), $formatter->formatBatch($records));
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 7
0
 public function formatBatch(array $records)
 {
     return parent::formatBatch(array_map(function (array $record) {
         return $this->mapRecord($record);
     }, $records));
 }
Ejemplo n.º 8
0
 /**
  * @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;
 }
 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']);
 }
Ejemplo n.º 10
0
 public function formatBatch(array $records)
 {
     $records = array_map('el_format_record', $records);
     return parent::formatBatch($records);
 }