[go: nahoru, domu]

Skip to content

cloudvox/phpbrake

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHPBrake Circle CI

Installation

composer require airbrake/phpbrake

Quickstart

// Create new Notifier instance.
$notifier = new \Airbrake\Notifier(array(
    'projectId' => 12345, // FIX ME
    'projectKey' => 'abcdefg', // FIX ME
));

// Set global notifier instance.
\Airbrake\Instance::set($notifier);

// Register error and exception handlers.
$handler = new \Airbrake\ErrorHandler($notifier);
$handler->register();

// Somewhere in the app...
try {
    throw new Exception('hello from phpbrake');
} catch(Exception $e) {
    \Airbrake\Instance::notify($e);
}

API

Notifier API constists of 4 methods:

  • buildNotice - builds Airbrake notice.
  • sendNotice - sends notice to Airbrake.
  • notify - shortcut for buildNotice and sendNotice.
  • addFilter - adds filter that can modify and/or filter notices.

Adding custom data to the notice

$notifier->addFilter(function ($notice) {
    $notice['context']['environment'] = 'production';
    return $notice;
});

Filtering sensitive data from the notice

$notifier->addFilter(function ($notice) {
    if (isset($notice['params']['password'])) {
        $notice['params']['password'] = 'FILTERED';
    }
    return $notice;
});

Ignoring specific exceptions

$notifier->addFilter(function ($notice) {
    if ($notice['errors'][0]['type'] == 'MyExceptionClass') {
        // Ignore this exception.
        return null;
    }
    return $notice;
});

Error handler

Notifier can handle PHP errors, uncatched exceptions and shutdown. You can register appropriate handlers using following code:

$handler = new \Airbrake\ErrorHandler($notifier);
$handler->register();

Under the hood $handler->register does following:

set_error_handler(array($this, 'onError'), error_reporting());
set_exception_handler(array($this, 'onException'));
register_shutdown_function(array($this, 'onShutdown'));

Monolog integration

$log = new \Monolog\Logger('billing');
$log->pushHandler(new \Airbrake\MonologHandler($notifier));

$log->addError('charge failed', array('client_id' => 123));

Running tests

composer install
bin/phpunit

PHPDoc

composer require phpdocumentor/phpdocumentor
bin/phpdoc -d src
firefox output/index.html