Exemple #1
0
 protected function normalize($data)
 {
     if (is_object($data) && !$data instanceof DateTime) {
         return $data;
     }
     return parent::normalize($data);
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function format(array $record)
 {
     $record = parent::format($record);
     if ($this->version === self::V1) {
         $message = $this->formatV1($record);
     } else {
         $message = $this->formatV0($record);
     }
     return $this->toJson($message) . "\n";
 }
 protected function normalize($data)
 {
     if (is_bool($data) || is_null($data)) {
         return var_export($data, true);
     }
     if ($data instanceof Exception) {
         $previousText = '';
         if (version_compare(PHP_VERSION, '5.3') >= 0 && ($previous = $data->getPrevious())) {
             do {
                 $previousText .= ', ' . get_class($previous) . ': ' . $previous->getMessage() . ' at ' . $previous->getFile() . ':' . $previous->getLine();
             } while ($previous = $previous->getPrevious());
         }
         return '[object] (' . get_class($data) . ': ' . $data->getMessage() . ' at ' . $data->getFile() . ':' . $data->getLine() . $previousText . ')';
     }
     return parent::normalize($data);
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function format(array $record)
 {
     $vars = parent::format($record);
     $output = $this->format;
     foreach ($vars['extra'] as $var => $val) {
         if (false !== strpos($output, '%extra.' . $var . '%')) {
             $output = str_replace('%extra.' . $var . '%', $this->replaceNewlines($this->convertToString($val)), $output);
             unset($vars['extra'][$var]);
         }
     }
     foreach ($vars as $var => $val) {
         if (false !== strpos($output, '%' . $var . '%')) {
             $output = str_replace('%' . $var . '%', $this->replaceNewlines($this->convertToString($val)), $output);
         }
     }
     return $output;
 }
 /**
  * {@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']);
     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;
 }
Exemple #6
0
 /**
  * @param string $dateFormat The format of the timestamp: one supported by DateTime::format
  */
 public function __construct($dateFormat = null)
 {
     parent::__construct($dateFormat);
 }
Exemple #7
0
 /**
  * {@inheritdoc}
  */
 public function format(array $record)
 {
     $record = parent::format($record);
     return $this->getDocument($record);
 }