/**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     $this->publishes([__DIR__ . '/config/config.php' => config_path('raven.php')], 'config');
     if (!config('raven.enabled')) {
         return;
     }
     $this->app['log']->registerHandler(config('raven.level', 'error'), function ($level) {
         $handler = new RavenHandler($this->app[Client::class], $level);
         // Add processors
         $processors = config('raven.monolog.processors', []);
         if (is_array($processors)) {
             foreach ($processors as $process) {
                 // Get callable
                 if (is_callable($process)) {
                     $callable = $process;
                 } elseif (is_string($process)) {
                     $callable = new $process();
                 } else {
                     throw new \Exception('Raven: Invalid processor');
                 }
                 // Add processor to Raven handler
                 $handler->pushProcessor($callable);
             }
         }
         return $handler;
     });
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function boot()
 {
     if (!$this->app->config->get('raven::enabled')) {
         return;
     }
     $this->app->log = new Log($this->app->log->getMonolog());
     $this->app->log->registerHandler($this->app->config->get('raven::level', 'error'), function ($level) {
         $handler = new RavenHandler($this->app['log.raven'], $level);
         // Add processors
         $processors = $this->app['log.raven.processors'];
         if (is_array($processors)) {
             foreach ($processors as $process) {
                 // Get callable
                 if (is_string($process)) {
                     $callable = new $process();
                 } elseif (is_callable($process)) {
                     $callable = $process;
                 } else {
                     throw new InvalidArgumentException('Raven: Invalid processor');
                 }
                 // Add processor to Raven handler
                 $handler->pushProcessor($callable);
             }
         }
         return $handler;
     });
 }
Пример #3
0
 /**
  * @param LoggerFactory $factory
  * @param string        $callbackUrl
  * @param bool          $debug
  */
 public static function attachSentry(LoggerFactory $factory, $callbackUrl, $debug)
 {
     if (true === $debug) {
         return;
     }
     $ravenClient = new \Raven_Client($callbackUrl);
     $sentryHandler = new RavenHandler($ravenClient, \Monolog\Logger::ERROR);
     $sentryHandler->setFormatter(new LineFormatter('%message% %context% %extra%\\n'));
     $factory->addHandler($sentryHandler);
     $factory->getLogger('app')->pushHandler($sentryHandler);
 }
 /**
  * Bootstraps Raven and Monolog together
  */
 private function bootstrapRaven()
 {
     $sentryEnabled = config('sentry.enabled', false);
     $sentryDsn = config('sentry.dsn', null);
     $sentryOptions = config('sentry.options', []);
     if ($sentryEnabled === true && !empty($sentryDsn)) {
         $client = new Raven_Client($sentryDsn, $sentryOptions);
         $handler = new RavenHandler($client);
         $handler->setFormatter(new LineFormatter("%message% %context% %extra%\n"));
         $monolog = Log::getMonolog();
         $monolog->pushHandler($handler);
     }
 }
Пример #5
0
 public function __construct()
 {
     /* copied functionality from system/core/Common.php, as the whole CI infrastructure is not available yet */
     if (!defined('ENVIRONMENT') or !file_exists($file_path = APPPATH . 'config/' . ENVIRONMENT . '/' . CONFIG_FILE)) {
         $file_path = APPPATH . 'config/' . CONFIG_FILE;
     }
     /* Fetch the config file */
     if (file_exists($file_path)) {
         require $file_path;
     } else {
         /* provide a reasonable standard config */
         $config = array('handler' => 'syslog', 'name' => 'codeigniter', 'channel' => 'codeigniter', 'formatter' => 'line', 'line_format' => '%channel%.%level_name%: %message%', 'syslog_facility' => 'local6', 'threshold' => '4');
     }
     $this->threshold = $config['threshold'];
     $this->log = new Logger($config['name']);
     /* decide which handler to use */
     switch ($config['handler']) {
         case 'syslog':
             $handler = new SyslogHandler($config['syslog_channel'], $config['syslog_facility']);
             break;
         case 'file':
             $handler = new StreamHandler($config['file_logfile']);
             break;
         case 'gelf':
             $publisher = new MessagePublisher($config['gelf_host'], $config['gelf_port']);
             $handler = new GelfHandler($publisher);
             break;
         case 'raven':
             $client = new Raven_Client($config['raven_endpoint']);
             $handler = new RavenHandler($client, Monolog\Logger::ERROR);
             break;
         default:
             exit('not supported log handler: ' . $config['handler']);
     }
     /* formatter selection, righht now only line formatter supported */
     switch ($config['formatter']) {
         case 'line':
             if (!isset($config['line_format'])) {
                 $formatter = new LineFormatter("%channel%.%level_name%: %message%");
             } else {
                 $formatter = new LineFormatter($config['line_format']);
             }
             break;
     }
     /* set formatter, and logging handler */
     if (isset($formatter)) {
         $handler->setFormatter($formatter);
     }
     $this->log->pushHandler($handler);
     $this->write_log('DEBUG', 'Monolog replacement logger initialized');
 }
Пример #6
0
 /**
  * Get Raven monolog handler.
  *
  * @return RavenHandler
  */
 protected function getHandler()
 {
     $handler = new RavenHandler($this->app[Client::class], $this->app['config']['raven.level']);
     $handler->setFormatter(new LineFormatter("%message% %context% %extra%\n"));
     return $handler;
 }