2017 © Pedro Peláez
 

craft-plugin craft3-bugsnag

Log Craft errors/exceptions to Bugsnag.

image

superbig/craft3-bugsnag

Log Craft errors/exceptions to Bugsnag.

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 3 Versions
  • 190 % Grown

The README.md

Bugsnag plugin for Craft CMS

Log Craft errors/exceptions to Bugsnag., (*1)

Installation

You can install Bugsnag via the plugin store, or through Composer., (*2)

Craft Plugin Store

To install Bugsnag, navigate to the Plugin Store section of your Craft control panel, search for Bugsnag, and click the Try button., (*3)

Composer

You can also add the package to your project using Composer., (*4)

  1. Open your terminal and go to your Craft project:, (*5)

    cd /path/to/project
  2. Then tell Composer to load the plugin:, (*6)

    composer require verbb/bugsnag
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Bugsnag., (*7)

Configuring Bugsnag

  1. Copy the config.php configuration file into your craft/config folder as bugsnag.php.
  2. Update serverApiKey with a API key from your Bugsnag project.
  3. (Optionally) Set the releaseStage configuration setting to something. Defaults to production.

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:, (*8)

'bootstrap' => [
    '\verbb\bugsnag\Bootstrap',
]

Blacklisting exceptions

If you want to ignore a certain type of exception, like a 404-error, you can do it like this:, (*9)

<?php

use yii\web\NotFoundHttpException;

return [
    'blacklist' => [
        [
            'label' => '404 errors etc',
            'class' => function($exception) {
                if ($exception instanceof NotFoundHttpException && $exception->statusCode === 404) {
                    return false;
                }

                return true;
            },
        ],
    ],  
];

Using Bugsnag

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:, (*10)

  • For exceptions: Bugsnag::$plugin->getService()->handleException($exception);

Using Bugsnag on the frontend

You can log JavaScript errors on your site, by including the following in your Twig templates:, (*11)

{% do view.registerAssetBundle('verbb\\bugsnag\\assetbundles\\frontend\\FrontEndAsset') %}

This currently uses v7.0.0 of the Bugsnag library., (*12)

You also need to set the browserApiKey setting., (*13)

If you'd rather include the Bugsnag client in your build and initialize it yourself, there is a helper method to get the browser config based on your plugin settings:, (*14)

<script>
    const bugsnagConfig = { ...{{ craft.bugsnag.getBrowserConfig(true) }} }
</script>

The method takes one parameter, that toggles if it should return JSON or not., (*15)

Adding metadata from templates

If you want to send custom metadata with your request, you may do something like this:, (*16)

{% do craft.bugsnag.metadata({ orderId: cart.id }) %}

Note that you have to call these methods before you include the JS bundle., (*17)

Throwing an exception from templates

You can trigger an exception from your templates., (*18)

{% do craft.bugsnag.handleException('Something went terribly wrong.') %}

Credits

Originally created by the team at Superbig., (*19)

Show your Support

Bugsnag is licensed under the MIT license, meaning it will always be free and open source – we love free stuff! If you'd like to show your support to the plugin regardless, Sponsor development., (*20)

, (*21)

The Versions

20/07 2018

dev-master

9999999-dev

Log Craft errors/exceptions to Bugsnag.

  Sources   Download

MIT

The Requires

 

cms bugsnag craftcms craft-plugin craft

20/07 2018

2.0.1

2.0.1.0

Log Craft errors/exceptions to Bugsnag.

  Sources   Download

MIT

The Requires

 

cms bugsnag craftcms craft-plugin craft

08/12 2017

2.0.0

2.0.0.0

Log Craft errors/exceptions to Bugsnag.

  Sources   Download

MIT

The Requires

 

cms bugsnag craftcms craft-plugin craft