baibaratsky/yii2-rollbar 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

baibaratsky/yii2-rollbar

最新稳定版本:v1.9.1

Composer 安装命令:

composer require baibaratsky/yii2-rollbar

包简介

Rollbar for Yii2

README 文档

README

Packagist Dependency Status Packagist Packagist

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

  1. Add the component configuration in your global main.php config 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']], // ], ], ],
  1. 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(), // ]; // }, ], ],
  1. 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.34k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 36
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 35
  • Watchers: 4
  • Forks: 23
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固