Skip to content

Commit

Permalink
Merge 5e2a744 into be232a8
Browse files Browse the repository at this point in the history
  • Loading branch information
nickfan committed Jun 25, 2016
2 parents be232a8 + 5e2a744 commit 3626386
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
/vendor
composer.lock
.DS_Store
*.iml
43 changes: 35 additions & 8 deletions src/RollbarServiceProvider.php
@@ -1,10 +1,15 @@
<?php namespace Jenssegers\Rollbar;

use Illuminate\Foundation\Application as LaravelApplication;
use Laravel\Lumen\Application as LumenApplication;

use Illuminate\Support\ServiceProvider;
use InvalidArgumentException;
use Rollbar;
use RollbarNotifier;

use Monolog\Handler\RollbarHandler;

class RollbarServiceProvider extends ServiceProvider
{
/**
Expand All @@ -20,18 +25,31 @@ class RollbarServiceProvider extends ServiceProvider
public function boot()
{
$app = $this->app;
if ($this->app instanceof LaravelApplication) {
// Listen to log messages.
$app['log']->listen(function ($level, $message, $context) use ($app) {
$app['Jenssegers\Rollbar\RollbarLogHandler']->log($level, $message, $context);
});
}elseif($this->app instanceof LumenApplication) {
// Listen to log messages.
$app['log']->pushHandler(
app(RollbarLogHandler::class, [
$this->app[Rollbar::class]
])
);
}

// Listen to log messages.
$app['log']->listen(function ($level, $message, $context) use ($app) {
$app['Jenssegers\Rollbar\RollbarLogHandler']->log($level, $message, $context);
});
}

/**
* Register the service provider.
*/
public function register()
{
if($this->app instanceof LumenApplication) {
$this->app->configure('services');
}

// Don't register rollbar if it is not configured.
if (! getenv('ROLLBAR_TOKEN') and ! $this->app['config']->get('services.rollbar')) {
return;
Expand Down Expand Up @@ -59,11 +77,20 @@ public function register()
return $rollbar;
});

$this->app['Jenssegers\Rollbar\RollbarLogHandler'] = $this->app->share(function ($app) {
$level = getenv('ROLLBAR_LEVEL') ?: $app['config']->get('services.rollbar.level', 'debug');
if ($this->app instanceof LaravelApplication) {
$this->app['Jenssegers\Rollbar\RollbarLogHandler'] = $this->app->share(function ($app) {
$level = getenv('ROLLBAR_LEVEL') ?: $app['config']->get('services.rollbar.level', 'debug');

return new RollbarLogHandler($app['RollbarNotifier'], $app, $level);
});
return new RollbarLogHandler($app['RollbarNotifier'], $app, $level);
});
}elseif($this->app instanceof LumenApplication) {
$app[RollbarLogHandler::class] = $app->share(function ($app) {
$level = getenv('ROLLBAR_LEVEL') ?: $app['config']->get('services.rollbar.level', 'debug');

$handler = app(RollbarHandler::class, [$this->app[RollbarNotifier::class], $level]);
return $handler;
});
}

// Register the fatal error handler.
register_shutdown_function(function () use ($app) {
Expand Down

0 comments on commit 3626386

Please sign in to comment.