This library integrates the Bugsnag error reporting library into your CakePHP 2.x project using composer install provided by https://bugsnag.com
- Register with Bugsnag and grab yourself an API key
- Install the Bugsnag library using composer
- Setup your project with the Bugsnag credentials and import statements in
bootstrap.php, add theBugsnagErrorHandler.phpclass underapp/vendors, and define new error handlers in andcore.php
Install the Bugsnag library via Composer (see official docs)
Open terminal and cd into your_project_repo/app and add requirement via composer
composer require "bugsnag/bugsnag:^3.0"
Then run composer to download and install the bugsnag official library
composer install
You should now have a new directory under your_project_repo/app/vendor with the bugsnag library and associated dependancies in.
Now you need to set up your project with the BugsnapErrorHandler.php class and make edits to the bootstrap.php and core.php configs
After installing the Bugsnag library via composer you need to edit two files: bootstrap.php and core.php.
Edit app/Config/bootstrap.php to include the API key provided by Bugsnag and include the BugsnagErrorHandler.php and autoloader via the App::import() function at the bottom of bootstrap.php.
// Enter your own Bugsnag API key in bootstrap.php
Configure::write('bugsnag_api_key', YOUR_BUGSNAG_API_KEY_HERE);
// Add these two lines at the bottom of your bootstrap.php file
App::import('Vendor', array('file' => 'autoload'));
App::import('vendors', array('file' => 'BugsnagErrorHandler'));Edit app/Config/core.php to override the default CakePHP Exception and Error handler class. Make sure to remove the existing Exception and Error configure options and replace them with the two lines below.
Configure::write('Exception', array(
'handler' => 'BugsnagErrorHandler::handleException',
'renderer' => 'ExceptionRenderer',
'log' => true
));
Configure::write('Error', array(
'handler' => 'BugsnagErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));You should now begin seeing bug reports in the bugsnag console.
Success!
- Composer - a tool for dependency management in PHP
- Cakephp 2.x - a rapid development framework for PHP
Andy Garbett - @garbit
This project is licensed under the MIT License - see the LICENSE.md file for details