sorokinmedia / yii2-rollbar
Rollbar for Yii2
Installs: 77
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 8
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=7.1
- rollbar/rollbar: ^1.8
- yiisoft/yii2: ^2.0.30
Requires (Dev)
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-11-05 00:27:13 UTC
README
This extension is the way to integrate Rollbar service with your Yii2 application.
Installation
The preferred way to install this extension is through composer.
To install, either run
$ php composer.phar require sorokinmedia/yii2-rollbar
or add
"sorokinmedia/yii2-rollbar": "dev-master"
to the require
section of your composer.json
file.
If you want to use it with Yii prior to 2.0.13, you need yii2-rollbar of the version 1.6.*
.
Usage
- Add the component configuration in your global
main.php
config file:
'bootstrap' => ['rollbar'], 'components' => [ 'rollbar' => [ 'class' => \sorokinmedia\rollbar\Rollbar::class, 'accessToken' => 'YOUR_ACCESS_TOKEN', 'environment' => 'local', 'root' => '@root', // You can specify exceptions to be ignored by yii2-rollbar: 'ignoreExceptions' => [ ['yii\web\HttpException', 'statusCode' => [400, 403, 404]], ['yii\web\ForbiddenHttpException', 'statusCode' => [403]], ['yii\web\UnauthorizedHttpException', 'statusCode' => [401,403]], ], ], ],
- Add the web error handler configuration in your web config file:
'components' => [ 'errorAction' => 'site/error', 'class' => \sorokinmedia\rollbar\web\ErrorHandler::class, // You can include additional data in a payload: 'payloadDataCallback' => function (\sorokinmedia\rollbar\web\ErrorHandler $errorHandler) { return [ 'exceptionCode' => $errorHandler->exception->getCode(), 'rawRequestBody' => Yii::$app->request->getRawBody(), ]; }, ],
- Add the console error handler configuration in your console config file:
'components' => [ 'errorHandler' => [ 'class' => \sorokinmedia\rollbar\console\ErrorHandler::class, ], ],
Log Target
You may want to collect your logs produced by Yii::error()
, Yii::info()
, etc. in Rollbar.
Put the following code in your config:
'log' => [ 'targets' => [ [ 'class' => \sorokinmedia\rollbar\log\Target::class, 'levels' => ['error', 'warning', 'info'], // Log levels you want to appear in Rollbar // It is highly recommended that you specify certain categories. // Otherwise, the exceptions and errors handled by the error handlers will be duplicated. 'categories' => ['application'], ], ], ],
The log target also appends category
and request_id
parameters to the log messages.
request_id
is useful if you want to have a yii2-debug-like grouping.