/** * Writes each of the messages into the collection * * @param array messages * @return void */ public function write(array $messages) { if ($this->_db === NULL) { // MangoDB instance $this->_db = MangoDB::instance($this->_name); } foreach ($messages as &$message) { $message['body'] = $this->format_message($message, 'body in file:line'); unset($message['additional'], $message['trace']); } try { $this->_db->batch_insert($this->_collection, $messages, $this->_options); } catch (MongoException $e) { // fallback to file logging if ($this->_log === NULL) { $this->_log = new Log_File(APPPATH . 'logs'); } $this->_log->write($messages); } }
/** * Return db reference * * @return MangoDB database object */ public function db() { if (!is_object($this->_db)) { // Initialize DB $this->_db = MangoDB::instance($this->_db); } return $this->_db; }