You are here

class MongoDbLog in MongoDB 8

Hierarchy

Expanded class hierarchy of MongoDbLog

1 string reference to 'MongoDbLog'
mongodb_dblog.services.yml in mongodb_dblog/mongodb_dblog.services.yml
mongodb_dblog/mongodb_dblog.services.yml
1 service uses MongoDbLog
mongodb.logger.dblog in mongodb_dblog/mongodb_dblog.services.yml
Drupal\mongodb_dblog\MongoDbLog

File

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

Namespace

Drupal\mongodb_dblog
View source
class MongoDbLog implements LoggerInterface {
  use RfcLoggerTrait;

  /**
   * MongoDB collection factory.
   *
   * @var \Drupal\mongodb\MongoCollectionFactory
   */
  protected $mongo;

  /**
   * The message's placeholders parser.
   *
   * @var \Drupal\Core\Logger\LogMessageParserInterface
   */
  protected $parser;

  /**
   * Constructs a DbLog object.
   *
   * @param \Drupal\mongodb\MongoCollectionFactory $mongo
   *   The mongo collection factory.
   * @param \Drupal\Core\Logger\LogMessageParserInterface $parser
   *   The parser to use when extracting message variables.
   */
  public function __construct(MongoCollectionFactory $mongo, LogMessageParserInterface $parser) {
    $this->mongo = $mongo;
    $this->parser = $parser;
  }

  /**
   * {@inheritdoc}
   */
  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'],
    ));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MongoDbLog::$mongo protected property MongoDB collection factory.
MongoDbLog::$parser protected property The message's placeholders parser.
MongoDbLog::log public function Overrides RfcLoggerTrait::log
MongoDbLog::__construct public function Constructs a DbLog object.
RfcLoggerTrait::alert public function
RfcLoggerTrait::critical public function
RfcLoggerTrait::debug public function
RfcLoggerTrait::emergency public function
RfcLoggerTrait::error public function
RfcLoggerTrait::info public function
RfcLoggerTrait::notice public function
RfcLoggerTrait::warning public function