/**
  * {@inheritdoc}
  */
 public function format(array $record)
 {
     $record = parent::format($record);
     $message = new Gelf_Message();
     $message->setTimestamp($record['datetime'])->setShortMessage((string) $record['message'])->setFacility($record['channel'])->setHost($this->systemName)->setLine(isset($record['extra']['line']) ? $record['extra']['line'] : null)->setFile(isset($record['extra']['file']) ? $record['extra']['file'] : null)->setLevel($this->logLevels[$record['level']]);
     // Do not duplicate these values in the additional fields
     unset($record['extra']['line']);
     unset($record['extra']['file']);
     if (isset($record['extra']['memory_usage'])) {
         $record['extra']['mem_usage'] = $record['extra']['memory_usage'];
         unset($record['extra']['memory_usage']);
     }
     if (isset($record['extra']['memory_peak_usage'])) {
         $record['extra']['mem_peak_usage'] = $record['extra']['memory_peak_usage'];
         unset($record['extra']['memory_peak_usage']);
     }
     foreach ($record['extra'] as $key => $val) {
         $message->setAdditional($this->extraPrefix . $key, is_scalar($val) ? $val : $this->toJson($val));
     }
     foreach ($record['context'] as $key => $val) {
         $message->setAdditional($this->contextPrefix . $key, is_scalar($val) ? $val : $this->toJson($val));
     }
     if (null === $message->getFile() && isset($record['context']['exception'])) {
         if (preg_match("/^(.+):([0-9]+)\$/", $record['context']['exception']['file'], $matches)) {
             $message->setFile($matches[1]);
             $message->setLine($matches[2]);
         }
     }
     return $message;
 }
Exemplo n.º 2
0
 /**
  * @param Gelf_Message $message
  *
  * @return string
  */
 protected function getPreparedMessage(Gelf_Message $message)
 {
     return gzcompress(json_encode($message->toArray()));
 }