Log Craft errors/exceptions to Bugsnag.
This plugin requires Craft CMS 3.0.0-RC1 or later.
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project
-
Then tell Composer to load the plugin:
composer require superbig/craft3-bugsnag
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for Bugsnag.
Bugsnag's cross platform error monitoring automatically detects crashes in your applications, letting you ship with confidence.
- Copy the config.php configuration file into your
craft/config
folder as bugsnag.php. - Update
serverApiKey
with a API key from your Bugsnag project. - (Optionally) Set the
releaseStage
configuration setting to something. Defaults toproduction
.
If you want to be able to capture early initialization errors, you need to add this plugin to your project's bootstrap configuration. To do this, in config/app.php
, add the following:
'bootstrap' => [ '\superbig\bugsnag\Bootstrap', ]
If you want to ignore a certain type of exception, like a 404-error, you can do it like this:
<?php
return [
'blacklist' => [
[
'label' => '404 errors etc',
'class' => function($exception) {
/**
* @var \yii\web\NotFoundHttpException $exception
*/
if ($exception instanceof \yii\web\NotFoundHttpException && $exception->statusCode === 404) {
return false;
}
return true;
},
],
],
];
It will automatically log most exceptions/errors. If you want to log a exceptions/error from an custom plugin, you may use the service methods:
- For exceptions:
Bugsnag::$plugin->bugsnagService->handleException($exception);
You can log JavaScript errors on your site, by including the following in your Twig templates:
{% do view.registerAssetBundle('superbig\\bugsnag\\assetbundles\\frontend\\FrontEndAsset') %}
Brought to you by Superbig