dev-master
9999999-dev https://github.com/brightlocal/php-airbrakeA PHP 5.3 library for sending errors to the Airbrake.io service.
MIT
The Requires
- php >=5.4
by Drew Butler
logging errors airbrake exceptions
A PHP 5.3 library for sending errors to the Airbrake.io service.
A PHP module to make use of the Airbrake API for storing error messages. This is based loosely on the official Ruby implementation from the Airbrake team., (*1)
The best way to install the library is by using Composer. Add the following to composer.json
in the root of your project:, (*2)
``` javascript { "require": { "brightlocal/php-airbrake": "dev-master" } }, (*3)
Then, on the command line: ``` bash curl -s http://getcomposer.org/installer | php php composer.phar install
Use the generated vendor/autoload.php
file to autoload the library classes., (*4)
The preferred method for this to be used is via error and exception handlers, so that you do not have to manually call the configuration and client class every time. This is simply done by calling up the built in error handler and passing in your API key to its start() method like so:, (*5)
<?php require_once 'vendor/autoload.php'; Airbrake\EventHandler::start('[your api key]');
Optionally, you may pass a second parameter as TRUE to the start() method, in order to enable the logging of warning level messages as well. This is disabled by default, as it may considered too noisy, depending on the quality of the code base. There is also a third options array that may be passed, which will load many of the more common configuration options. These options are located below., (*6)
If calling the class directly and not through an exception handler, it would be done like this:, (*7)
<?php require_once 'vendor/autoload.php'; $apiKey = '[your api key]'; // This is required $options = []; // This is optional $config = new Airbrake\Configuration($apiKey, $options); $client = new Airbrake\Client($config); // Send just an error message $client->notifyOnError('My error message'); // Send an exception that may have been generated or caught. try { throw new Exception('This is my exception'); } catch (Exception $exception) { $client->notifyOnException($exception); }
The options array may be filled with data from the Configuration Options section, if you would like to override some of the default options. Otherwise, it can be ignored., (*8)
You can use external classes to handle non-standard handling of notifications, e.g. using asynchronous sending to avoid delays introduced by the need to make extra curl posts., (*9)
To use custom handler, create a class that implements Airbrake\Interfaces\NotificationHandler interface, and pass an instance to the config:, (*10)
<?php require_once 'vendor/autoload.php'; Airbrake\EventHandler::start( '[your api key]', true, [ 'notificationHandler' => new MyNotificationHandler(), ] );
A PHP 5.3 library for sending errors to the Airbrake.io service.
MIT
logging errors airbrake exceptions