diff options
Diffstat (limited to 'vendor/monolog/monolog/src/Monolog/Formatter/GelfMessageFormatter.php')
-rw-r--r-- | vendor/monolog/monolog/src/Monolog/Formatter/GelfMessageFormatter.php | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/vendor/monolog/monolog/src/Monolog/Formatter/GelfMessageFormatter.php b/vendor/monolog/monolog/src/Monolog/Formatter/GelfMessageFormatter.php index 8d01c64c..1e431750 100644 --- a/vendor/monolog/monolog/src/Monolog/Formatter/GelfMessageFormatter.php +++ b/vendor/monolog/monolog/src/Monolog/Formatter/GelfMessageFormatter.php @@ -67,19 +67,29 @@ class GelfMessageFormatter extends NormalizerFormatter public function format(array $record) { $record = parent::format($record); + + if (!isset($record['datetime'], $record['message'], $record['level'])) { + throw new \InvalidArgumentException('The record should at least contain datetime, message and level keys, '.var_export($record, true).' given'); + } + $message = new 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['channel'])) { + $message->setFacility($record['channel']); + } + if (isset($record['extra']['line'])) { + $message->setLine($record['extra']['line']); + unset($record['extra']['line']); + } + if (isset($record['extra']['file'])) { + $message->setFile($record['extra']['file']); + unset($record['extra']['file']); + } foreach ($record['extra'] as $key => $val) { $message->setAdditional($this->extraPrefix . $key, is_scalar($val) ? $val : $this->toJson($val)); |