Skip to content

Commit

Permalink
Register fatal error handler and tweaks for flushing
Browse files Browse the repository at this point in the history
jenssegers committed May 24, 2015
1 parent ed6d75b commit 58cb2db
Showing 2 changed files with 19 additions and 43 deletions.
42 changes: 19 additions & 23 deletions src/RollbarServiceProvider.php
Original file line number Diff line number Diff line change
@@ -28,29 +28,6 @@ public function boot()
{
$app['rollbar.handler']->log($level, $message, $context);
});

// Flush callback
$flush = function () use ($app)
{
if ($app->resolved('rollbar.client'))
{
$app['rollbar.client']->flush();
}
};

if (method_exists($app, 'version') and starts_with($app->version(), '5'))
{
// Register Laravel 5 shutdown function
$this->app->terminating($flush);
}
else
{
// Register Laravel 4 shutdown function
$this->app->shutdown($flush);
}

// Register PHP shutdown function
register_shutdown_function($flush);
}

/**
@@ -84,6 +61,25 @@ public function register()

return new RollbarLogHandler($client, $app, $level);
});

// If the Rollbar client was resolved, then there is a possibility that there
// are unsent error messages in the internal queue, so let's flush them.
register_shutdown_function(function () use ($app)
{
if ($app->resolved('rollbar.client'))
{
$app['rollbar.client']->flush();
}
});

// Register the fatal error handler.
register_shutdown_function(function () use ($app)
{
if (isset($app['rollbar.client']))
{
Rollbar::report_fatal_error();
}
});
}

}
20 changes: 0 additions & 20 deletions tests/RollbarTest.php
Original file line number Diff line number Diff line change
@@ -161,24 +161,4 @@ public function testAboveLevel()
$this->app->log->emergency('hello');
}

public function testFlushOnTerminate()
{
$clientMock = Mockery::mock('RollbarNotifier');
$clientMock->shouldReceive('flush')->once();
$this->app['rollbar.client'] = $clientMock;

$handler = $this->app->make('rollbar.handler');

$this->app->terminate();
}

public function testDontFlushIfUnresolved()
{
$clientMock = Mockery::mock('RollbarNotifier');
$clientMock->shouldReceive('flush')->times(0);
$this->app['rollbar.client'] = $clientMock;

$this->app->terminate();
}

}

0 comments on commit 58cb2db

Please sign in to comment.