You are here

public function MongoDbLog::log in MongoDB 8

Overrides RfcLoggerTrait::log

File

mongodb_dblog/src/MongoDbLog.php, line 49
Contains \Drupal\mongodb\MongoDbLog.

Class

MongoDbLog

Namespace

Drupal\mongodb_dblog

Code

public function log($level, $message, array $context = array()) {

  // Remove any backtraces since they may contain an unserializable variable.
  unset($context['backtrace']);

  // Convert PSR3-style messages to String::format() style, so they can be
  // translated too in runtime.
  $message_placeholders = $this->parser
    ->parseMessagePlaceholders($message, $context);
  $this->mongo
    ->get('watchdog')
    ->insert(array(
    'uid' => $context['uid'],
    'type' => substr($context['channel'], 0, 64),
    'message' => $message,
    'variables' => serialize($message_placeholders),
    'severity' => $level,
    'link' => substr($context['link'], 0, 255),
    'location' => $context['request_uri'],
    'referer' => $context['referer'],
    'hostname' => substr($context['ip'], 0, 128),
    'timestamp' => $context['timestamp'],
  ));
}