baibaratsky/yii2-rollbar
最新稳定版本:v1.9.1
Composer 安装命令:
composer require baibaratsky/yii2-rollbar
包简介
Rollbar for Yii2
README 文档
README
This extension is the way to integrate Rollbar service with your Yii2 application. For Yii 1.* use yii-rollbar.
Installation
The preferred way to install this extension is through composer.
To install, either run
$ php composer.phar require baibaratsky/yii2-rollbar:1.9.*
or add
"baibaratsky/yii2-rollbar": "1.9.*"
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.phpconfig file:
'bootstrap' => ['rollbar'], 'components' => [ 'rollbar' => [ 'class' => 'baibaratsky\yii\rollbar\Rollbar', 'accessToken' => 'POST_SERVER_ITEM_ACCESS_TOKEN', // You can specify exceptions to be ignored by yii2-rollbar: // 'ignoreExceptions' => [ // ['yii\web\HttpException', 'statusCode' => [400, 404]], // ['yii\web\HttpException', 'statusCode' => [403], 'message' => ['This action is forbidden']], // ], ], ],
- Add the web error handler configuration in your web config file:
'components' => [ 'errorHandler' => [ 'class' => 'baibaratsky\yii\rollbar\web\ErrorHandler', // You can include additional data in a payload: // 'payloadDataCallback' => function (\baibaratsky\yii\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' => 'baibaratsky\yii\rollbar\console\ErrorHandler', ], ],
Payload from your exceptions
If you want your exceptions to send some additional data to Rollbar,
it is possible by implementing the WithPayload interface.
use baibaratsky\yii\rollbar\WithPayload; class SomeException extends \Exception implements WithPayload { public function rollbarPayload() { return ['foo' => 'bar']; } }
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' => 'baibaratsky\yii\rollbar\log\Target', '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.
统计信息
- 总下载量: 128.38k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 36
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-07-30