-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ca3d826
Showing
9 changed files
with
361 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/vendor | ||
composer.lock | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: php | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
|
||
before_script: | ||
- composer self-update | ||
- composer require satooshi/php-coveralls:dev-master | ||
- composer install --dev --no-interaction | ||
|
||
script: | ||
- mkdir -p build/logs | ||
- phpunit --coverage-clover build/logs/clover.xml | ||
|
||
after_script: | ||
- php vendor/bin/coveralls -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
Laravel Rollbar | ||
=============== | ||
|
||
[](https://travis-ci.org/jenssegers/Laravel-Rollbar) [](https://coveralls.io/r/jenssegers/Laravel-Rollbar) | ||
|
||
Rollbar error monitoring integration for Laravel projects. | ||
|
||
Installation | ||
------------ | ||
|
||
Add the package to your `composer.json` and run `composer update`. | ||
|
||
{ | ||
"require": { | ||
"jenssegers/rollbar": "*" | ||
} | ||
} | ||
|
||
Add the service provider in `app/config/app.php`: | ||
|
||
'Jenssegers\Rollbar\RollbarServiceProvider', | ||
|
||
Add the Rollbar alias to `app/config/app.php`: | ||
|
||
'Rollbar' => 'Jenssegers\Rollbar\Facades\Rollbar', | ||
|
||
Configuration | ||
------------- | ||
|
||
Publish the included configuration file: | ||
|
||
php artisan config:publish jenssegers/rollbar | ||
|
||
And change your rollbar access token: | ||
|
||
'token' => '', | ||
|
||
Usage | ||
----- | ||
|
||
The service provider will make sure all your exceptions and log messages are passed to Rollbar automatically. | ||
|
||
throw new Exception('Something went wrong'); | ||
|
||
Or if you want to directly send the exception object: | ||
|
||
Log::error(new Exception('Something went wrong')); | ||
|
||
Your log messages will also be sent to Rollbar: | ||
|
||
Log::info('Hello Rollbar', array('context')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "jenssegers/rollbar", | ||
"description": "Rollbar error monitoring integration for Laravel projects", | ||
"keywords": ["laravel", "rollbar", "monitoring", "error", "logging"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Jens Segers", | ||
"homepage": "http://jenssegers.be" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3", | ||
"rollbar/rollbar": "*" | ||
}, | ||
"require-dev": { | ||
"orchestra/testbench": "2.1.*", | ||
"mockery/mockery": "*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Jenssegers\\Rollbar\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="true" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php namespace Jenssegers\Rollbar\Facades; | ||
|
||
use \Illuminate\Support\Facades\Facade; | ||
|
||
class Rollbar extends Facade { | ||
|
||
/** | ||
* Get the registered name of the component. | ||
* | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() { return 'rollbar'; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php namespace Jenssegers\Rollbar; | ||
|
||
use App; | ||
use Config; | ||
use Exception; | ||
use RollbarNotifier; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class RollbarServiceProvider extends ServiceProvider { | ||
|
||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* Bootstrap the application events. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->package('jenssegers/rollbar'); | ||
|
||
// Register error listener | ||
$this->app->error(function(Exception $exception) | ||
{ | ||
$rollbar = App::make('rollbar'); | ||
$rollbar->report_exception($exception); | ||
}); | ||
|
||
// Register log listener | ||
$this->app->log->listen(function($level, $message, $context) | ||
{ | ||
$rollbar = App::make('rollbar'); | ||
|
||
if ($message instanceof Exception) | ||
{ | ||
$rollbar->report_exception($message); | ||
} | ||
else | ||
{ | ||
$rollbar->report_message($message, $level, $context); | ||
} | ||
}); | ||
|
||
// Register after filter | ||
$this->app->after(function() | ||
{ | ||
$rollbar = App::make('rollbar'); | ||
$rollbar->flush(); | ||
}); | ||
} | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->bindShared('rollbar', function($app) | ||
{ | ||
$config = array( | ||
'access_token' => Config::get('rollbar::token'), | ||
'environment' => App::environment(), | ||
'root' => base_path(), | ||
'max_errno' => Config::get('rollbar::max_errno'), | ||
'person' => Config::get('rollbar::person'), | ||
); | ||
|
||
return new RollbarNotifier($config); | ||
}); | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return array('rollbar'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
return array( | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Rollbar access token | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This is your 'post_server_item' access token for the Rollbar API. This | ||
| token can be found in the 'Project Access Tokens' section in | ||
| your project settings. | ||
| | ||
*/ | ||
|
||
'token' => '', | ||
|
||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| User identification | ||
|-------------------------------------------------------------------------- | ||
| | ||
| An associative array containing data about the currently-logged in user. | ||
| Required: id, optional: username, email. All values are strings. | ||
| | ||
*/ | ||
|
||
'person' => array( | ||
|
||
), | ||
|
||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Maximum error number to report | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Default: ignore E_STRICT and above. | ||
| | ||
*/ | ||
|
||
'max_errno' => E_USER_NOTICE, | ||
|
||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
use Jenssegers\Rollbar\Facades\Rollbar; | ||
|
||
class ServiceProviderTest extends Orchestra\Testbench\TestCase { | ||
|
||
public function tearDown() | ||
{ | ||
Mockery::close(); | ||
} | ||
|
||
protected function getPackageProviders() | ||
{ | ||
return array('Jenssegers\Rollbar\RollbarServiceProvider'); | ||
} | ||
|
||
protected function getPackageAliases() | ||
{ | ||
return array( | ||
'Rollbar' => 'Jenssegers\Rollbar\Facades\Rollbar' | ||
); | ||
} | ||
|
||
public function testBinding() | ||
{ | ||
$rollbar = App::make('rollbar'); | ||
$this->assertInstanceOf('RollbarNotifier', $rollbar); | ||
} | ||
|
||
public function testIsFacade() | ||
{ | ||
$this->assertInstanceOf('RollbarNotifier', Rollbar::getFacadeRoot()); | ||
} | ||
|
||
public function testPassConfiguration() | ||
{ | ||
$person = array('id' => uniqid(), 'username' => 'johndoe'); | ||
$token = 'B42nHP04s06ov18Dv8X7VI4nVUs6w04X'; | ||
|
||
Config::set('rollbar::token', $token); | ||
Config::set('rollbar::person', $person); | ||
|
||
$rollbar = App::make('rollbar'); | ||
$this->assertEquals($token, $rollbar->access_token); | ||
$this->assertEquals($person, $rollbar->person); | ||
} | ||
|
||
public function testIsSingleton() | ||
{ | ||
$rollbar1 = App::make('rollbar'); | ||
$rollbar2 = App::make('rollbar'); | ||
$this->assertEquals(spl_object_hash($rollbar1), spl_object_hash($rollbar2)); | ||
} | ||
|
||
public function testEnvironment() | ||
{ | ||
$rollbar = App::make('rollbar'); | ||
$this->assertEquals(App::environment(), $rollbar->environment); | ||
$this->assertEquals(base_path(), $rollbar->root); | ||
//$this->assertEquals(E_USER_NOTICE, $rollbar->max_errno); | ||
} | ||
|
||
public function testRegisterErrorListener() | ||
{ | ||
$exception = new Exception('Testing error handler'); | ||
|
||
$mock = Mockery::mock('RollbarNotifier'); | ||
$mock->shouldReceive('report_exception')->once()->with($exception); | ||
$this->app->instance('rollbar', $mock); | ||
|
||
$handler = $this->app->exception; | ||
$response = (string) $handler->handleException($exception); | ||
} | ||
|
||
public function testRegisterLogListener() | ||
{ | ||
$exception = new Exception('Testing error handler'); | ||
|
||
$mock = Mockery::mock('RollbarNotifier'); | ||
$mock->shouldReceive('report_message')->once()->with('hello', 'info', array()); | ||
$mock->shouldReceive('report_message')->once()->with('oops', 'error', array('context')); | ||
$mock->shouldReceive('report_exception')->once()->with($exception); | ||
$this->app->instance('rollbar', $mock); | ||
|
||
Log::info('hello'); | ||
Log::error('oops', array('context')); | ||
Log::error($exception); | ||
} | ||
|
||
public function testFlush() | ||
{ | ||
$mock = Mockery::mock('RollbarNotifier'); | ||
$mock->shouldReceive('flush')->once(); | ||
$this->app->instance('rollbar', $mock); | ||
|
||
Route::enableFilters(); | ||
Event::fire('router.after'); | ||
} | ||
|
||
} |