public function DrupalHandler::write in Monolog 2.x
Same name and namespace in other branches
- 8 src/Logger/Handler/DrupalHandler.php \Drupal\monolog\Logger\Handler\DrupalHandler::write()
File
- src/
Logger/ Handler/ DrupalHandler.php, line 46
Class
- DrupalHandler
- Forwards logs to a Drupal logger.
Namespace
Drupal\monolog\Logger\HandlerCode
public function write(array $record) : void {
// Set up context with the data Drupal loggers expect.
// @see Drupal\Core\Logger\LoggerChannel::log()
$context = $record['context'] + [
'channel' => $record['channel'],
'link' => '',
'user' => isset($record['extra']['user']) ? $record['extra']['user'] : NULL,
'uid' => isset($record['extra']['uid']) ? $record['extra']['uid'] : 0,
'request_uri' => isset($record['extra']['request_uri']) ? $record['extra']['request_uri'] : '',
'referer' => isset($record['extra']['referer']) ? $record['extra']['referer'] : '',
'ip' => isset($record['extra']['ip']) ? $record['extra']['ip'] : 0,
'timestamp' => $record['datetime']
->format('U'),
];
$level = static::$levels[$record['level']];
$this->logger
->log($level, $record['message'], $context);
}