Sentry Integration for Laravel 4
Sentry (getsentry.com) and Laravel 4 integration.
Automatically send Laravel log messages to Sentry. This package integrates Sentry and Laravel 4 in a super simple way. Let's see how it works., (*1)
Installation
The package can be installed via Composer by requiring the
jcf/getsentry
package in your project's composer.json
., (*2)
{
"require": {
"jcf/getsentry": "1.1.*"
}
}
Then run a composer update, (*3)
php composer.phar update
After updating composer, add the ServiceProvider to the providers array in app/config/app.php, (*4)
'Jcf\Getsentry\GetsentryServiceProvider',
Configuration
Run php artisan config:publish jcf/getsentry to publish the configuration file., (*5)
php artisan config:publish jcf/getsentry
Edit the configuration file at /app/config/packages/jcf/getsentry. You may also create environment specific configuration files for your package by placing them in app/config/packages/jcf/getsentry/dev by example., (*6)
Options
Provide Sentry DSN of your project. You can grab this at Settings Tab / API Keys of your project on getsentry.com., (*7)
return array(
'dsn' => 'https://1f68584cfb824d123432534ab452adb778:7e06629189c02355bd2b928881a4c1f1@app.getsentry.com/26241',
Then set the environments that should be reported to Sentry., (*8)
'environments' => ['stagging', 'production'],
Set the log levels that should be reported to Sentry., (*9)
'environments' => ['error', 'emergency', 'notice', 'info', 'debug'],
Set if Sentry Event ID should be saved in session. This is useful if you want to share the event ID with your users., (*10)
'saveEventId' => true,
Usage
Automatically every message that will be logged by Laravel and that fits in rules of configuration will be sent to Sentry., (*11)
If you need, you may also trigger Laravel log mannualy and pass extra data to Sentry., (*12)
// Debug with User and Extra Data
\Log::debug('Debugging', [
'user' => [
'id' => 99,
'email' => 'joao@3eengenharia.com.br',
'data' =>[
'Member Since' => '2011-09-07'
]
]
, 'extra' => ['Ammount' => '142', 'Membership' => 'Activated']]
);
// Debug with User
\Log::debug('Debug bug!', ['user' => 'jotafurtado']);
// Info with User
\Log::info('User has logged in.', ['user' => 'jotafurtado']);
// Simple Error
\Log::error('Image not saved.');
To retrieve event ID use the code:, (*13)
\Session::get('sentryEventId');