示例#1
0
 public function log($message, $priority = self::INFO)
 {
     $parent = parent::log($message, $priority);
     $checked = array(self::CRITICAL, self::ERROR);
     if (defined('self::EXCEPTION')) {
         $checked[] = self::EXCEPTION;
     }
     if (in_array($priority, $checked, TRUE)) {
         $index = NULL;
         $trace = debug_backtrace(FALSE);
         if (!Tracy\Helpers::findTrace($trace, 'Tracy\\Debugger::log', $index)) {
             if (!Tracy\Helpers::findTrace($trace, 'Nette\\Diagnostics\\Debugger::log', $index)) {
                 Tracy\Helpers::findTrace($trace, 'log', $index);
             }
         }
         $errorTrace = $trace[$index + 1];
         //get trace for _errorHandler call
         $exceptionTrace = $trace[$index];
         //get trace for _exception or ::log call
         //if()
         $exception = NULL;
         if (isset($errorTrace['args']) && count($errorTrace['args']) == 5) {
             $exception = new \ErrorException($errorTrace['args'][1], 0, $errorTrace['args'][0], $errorTrace['args'][2], $errorTrace['args'][3]);
         } elseif (!empty($exceptionTrace['args']) && !empty($exceptionTrace['args'][0]) && $exceptionTrace['args'][0] instanceof \Exception) {
             $exception = $exceptionTrace['args'][0];
         }
         if ($exception) {
             $error = Consumerr::addError($exception);
             if ($error && is_array($message)) {
                 $error->addData('file', Tracy\Debugger::$logDirectory . '/' . substr($message[3], 5));
             }
         }
     }
     return $parent;
 }
示例#2
0
 private static function encodeData($param)
 {
     $encoding = 'plain';
     if (Consumerr::getConfiguration()->isCompressionEnabled()) {
         $encoding = 'gzip';
         $param = gzcompress($param);
     }
     return array(base64_encode($param), $encoding);
 }
示例#3
0
 public function send($data, $encoding)
 {
     $header = array('appSecret' => 'X-Consumerr-secret: ' . $this->configuration->getToken(), 'X-Consumerr-Encoding: ' . $encoding);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->configuration->getApiEndpoint());
     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
     curl_setopt($ch, CURLOPT_NOBODY, TRUE);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ch, CURLOPT_POST, TRUE);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_TIMEOUT, 2);
     curl_exec($ch);
     if ($this->configuration->getLogFile()) {
         //logging enabled
         if (curl_errno($ch) !== 0) {
             Consumerr::log("Transmission error - " . curl_error($ch));
         }
         $info = curl_getinfo($ch);
         if ($info['http_code'] != 200) {
             Consumerr::log("Transmission error - API returned HTTP " . $info['http_code']);
         }
     }
     @curl_close($ch);
 }
示例#4
0
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig($this->defaultOptions);
     if ($config['enable'] === NULL) {
         $config['enable'] = !$this->getContainerBuilder()->parameters['debugMode'];
     }
     if (!$config['enable']) {
         $this->enabled = FALSE;
         Consumerr::log('Nette Consumerr extension disabled by Neon configuration or detected debug mode.');
         return;
     }
     if (!empty($config['log']) && is_bool($config['log'])) {
         $dir = isset($this->getContainerBuilder()->parameters['logDir']) ? $this->getContainerBuilder()->parameters['logDir'] : Debugger::$logDirectory;
         if ($dir) {
             $config['log'] = $dir . '/consumerr.log';
         }
     }
     $builder->addDefinition($this->prefix('consumerr'))->setClass('Consumerr\\' . 'NetteConsumerr')->setAutowired(FALSE);
     $builder->addDefinition($this->prefix('configuration'))->setClass('Consumerr\\' . 'Configuration', array($config))->setAutowired(FALSE);
     /*if ($config['cache']['enable'] === TRUE) {
     			$consumerr->addSetup('setCache');
     		}*/
 }
示例#5
0
 /**
  * @param Nette\Application\Application $app
  * @param \Exception $e
  */
 public function onError(Nette\Application\Application $app, \Exception $e)
 {
     if ($e instanceof Nette\Application\BadRequestException) {
         return;
     }
     Consumerr::addError($e);
 }