/** * Log a message to the logs. * * @param string $level * @param mixed $message * @param array $context * * @return void */ public function log($level, $message, array $context = []) { if (isset($context['title'])) { $title = $context['title']; unset($context['title']); } $msg = $this->formatMessage($message); $title = $this->limit(isset($title) ? $title : (string) $msg); if ($level === 'debug' || $level === 'info') { if ($message instanceof Exception || $message instanceof Throwable) { $title = get_class($message); $data = ['name' => $title, 'message' => $message->getMessage()]; } else { $data = ['message' => $message]; } $metaData = array_merge(array_merge($data, ['severity' => $level]), $context); $this->client->leaveBreadcrumb($title, 'log', array_filter($metaData)); return; } $callback = function (Report $report) use($level, $context) { $report->setMetaData($context); $report->setSeverity($this->getSeverity($level)); }; if ($message instanceof Exception || $message instanceof Throwable) { $this->client->notifyException($message, $callback); } else { $this->client->notifyError($title, $msg, $callback); } }
public function register(Container $app) { $app['bugsnag'] = function ($app) { $client = Client::make($app['bugsnag.options']['apiKey']); $client->setNotifier(['name' => 'Silex Bugsnag', 'version' => static::VERSION, 'url' => 'https://github.com/fortis/silex-bugsnag']); Handler::register($client); return $client; }; $app->error(function (\Exception $error, Request $request) use($app) { $params['request'] = ['params' => $request->query->all(), 'requestFormat' => $request->getRequestFormat()]; $app['bugsnag']->notifyException($error); }); }
/** * Setup the client paths. * * @param \Bugsnag\Client $client * @param string|null $strip * @param string|null $project * * @return void */ protected function setupPaths(Client $client, $strip, $project) { if ($strip) { $client->setStripPath($strip); if (!$project) { $client->setProjectRoot("{$strip}/src"); } return; } $base = realpath(__DIR__ . '/../../../../'); if ($project) { if ($base && substr($project, 0, strlen($base)) === $base) { $client->setStripPath($base); } $client->setProjectRoot($project); return; } if ($base) { $client->setStripPath($base); if ($root = realpath("{$base}/src")) { $client->setProjectRoot($root); } } }
/** * Register the service provider. * * @return void */ public function register() { $this->app->singleton('bugsnag', function ($app) { $config = $app['config']['bugsnag']; $bugsnagConfig = new Configuration($config['api_key']); $client = new Client($bugsnagConfig); $client->setStripPath(base_path()); $client->setProjectRoot(base_path('app')); $client->setBatchSending(false); $client->setReleaseStage($app->environment()); $client->setNotifier(array('name' => 'Bugsnag Laravel', 'version' => '1.4.2', 'url' => 'https://github.com/bugsnag/bugsnag-laravel')); if (isset($config['notify_release_stages']) && is_array($config['notify_release_stages'])) { $client->setNotifyReleaseStages($config['notify_release_stages']); } if (isset($config['endpoint'])) { $client->setEndpoint($config['endpoint']); } if (isset($config['filters']) && is_array($config['filters'])) { $client->setFilters($config['filters']); } if (isset($config['proxy']) && is_array($config['proxy'])) { $client->setProxySettings($config['proxy']); } // Check if someone is logged in. try { if ($app['auth']->check()) { // User is logged in. $user = $app['auth']->user(); // If these attributes are available: pass them on. $client->setUser(array('id' => $user->getAuthIdentifier())); } } catch (\Exception $e) { // Do nothing. } return $client; }); }
/** * Setup the client paths. * * @param \Bugsnag\Client $client * @param string $base * @param string $path * @param string|null $strip * @param string|null $project * * @return void */ protected function setupPaths(Client $client, $base, $path, $strip, $project) { if ($strip) { $client->setStripPath($strip); if (!$project) { $client->setProjectRoot("{$strip}/app"); } return; } if ($project) { if ($base && substr($project, 0, strlen($base)) === $base) { $client->setStripPath($base); } $client->setProjectRoot($project); return; } $client->setStripPath($base); $client->setProjectRoot($path); }