Esempio n. 1
0
 /**
  * Logs a query to Sentry.
  * @param string $query query to log.
  * @param integer $level log level.
  * @param string $engine name of the sql driver.
  * @return string event id (or null if not captured).
  * @throws Exception if logging the query fails.
  */
 public function captureQuery($query, $level = Logger::LEVEL_INFO, $engine = '')
 {
     if (!$this->isEnvironmentEnabled()) {
         return null;
     }
     try {
         $eventId = $this->_client->getIdent($this->_client->captureQuery($query, $level, $engine));
     } catch (\Exception $e) {
         if (YII_DEBUG) {
             throw new Exception('SentryClient failed to log query: ' . $e->getMessage(), (int) $e->getCode());
         } else {
             $this->log($e->getMessage(), Logger::LEVEL_ERROR);
             throw new Exception('SentryClient failed to log query.', (int) $e->getCode());
         }
     }
     $this->_loggedEventIds[] = $eventId;
     $this->log(sprintf('Query logged to Sentry with event id: %d', $eventId), Logger::LEVEL_INFO);
     return $eventId;
 }
Esempio n. 2
0
 /**
  * Export the message
  *
  * @param array $content Array containing the info about the message
  * @return void
  */
 public function export($content)
 {
     global $conf;
     $dsn = $conf->global->SYSLOG_SENTRY_DSN;
     $client = new Raven_Client($dsn, array('curl_method' => 'exec'));
     $client->user_context(array('username' => $content['user'] ? $content['user'] : '', 'ip_address' => $content['ip']));
     $client->tags_context(array('version' => DOL_VERSION));
     $client->registerSeverityMap(array(LOG_EMERG => Raven_Client::FATAL, LOG_ALERT => Raven_Client::FATAL, LOG_CRIT => Raven_Client::ERROR, LOG_ERR => Raven_Client::ERROR, LOG_WARNING => Raven_Client::WARNING, LOG_NOTICE => Raven_Client::WARNING, LOG_INFO => Raven_Client::INFO, LOG_DEBUG => Raven_Client::DEBUG));
     if (substr($content['message'], 0, 3) === 'sql') {
         global $db;
         $query = substr($content['message'], 4, strlen($content['message']));
         $client->captureQuery($query, $client->translateSeverity($content['level']), $db->type);
     } else {
         $client->captureMessage($content['message'], null, $client->translateSeverity($content['level']));
     }
 }