Code Monkey home page Code Monkey logo

yii2-rollbar's Introduction

Rollbar for Yii2

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.7.*

or add

"baibaratsky/yii2-rollbar": "1.7.*"

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.

yii2-rollbar's People

Contributors

baibaratsky avatar friek108 avatar gelige avatar lgelfan avatar niektenhoopen avatar rokob avatar skjb avatar yumgame avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.