sorokinmedia / yii2-rollbar
为 Yii2 的 Rollbar
dev-master
2020-01-04 14:09 UTC
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-09-05 00:13:26 UTC
README
此扩展是集成 Rollbar 服务到您的 Yii2 应用的方式。
安装
安装此扩展的首选方式是通过 composer。
要安装,请运行
$ php composer.phar require sorokinmedia/yii2-rollbar
或者将以下内容添加到您的 composer.json
文件的 require
部分:
"sorokinmedia/yii2-rollbar": "dev-master"
如果您想使用 2.0.13 之前的 Yii,则需要使用 1.6.*
版本的 yii2-rollbar。
使用方法
- 在您的 全局
main.php
配置文件中添加组件配置
'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]], ], ], ],
- 在您的 web 配置文件中添加 web 错误处理器配置
'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(), ]; }, ],
- 在您的 console 配置文件中添加 console 错误处理器配置
'components' => [ 'errorHandler' => [ 'class' => \sorokinmedia\rollbar\console\ErrorHandler::class, ], ],
日志目标
您可能想将 Yii::error()
、Yii::info()
等生成的日志收集到 Rollbar 中。在您的配置中放置以下代码:
'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'], ], ], ],
日志目标还会将 category
和 request_id
参数附加到日志消息中。如果想要有类似 yii2-debug 的分组,request_id
将非常有用。