yii-rollbar Rollbar Yii Component

Rollbar Yii Component is the way to integrate Rollbar service with your Yii application. Rollbar aggregates and analyzes your application errors and deploys.

Installation ΒΆ

  1. a. Easy way is to use Composer. Just run composer install.

    OR

    b. Download rollbar.php and put it somewhere you can access, then add the following code at your application's entry point:

require_once 'rollbar.php';
   ~~~

2. Add `rollbar` component to the `main.php` config:
    ~~~
[php]
    // ...
    'components' => array(
        // ...
        'rollbar' => array(
            'class' => 'application.vendor.baibaratsky.yii-rollbar.RollbarComponent', // adjust path if needed
            'accessToken' => 'your_serverside_rollbar_token',
        ),
    ),
    ~~~

3. Adjust `main.php` config to preload the component:
    ~~~
[php]
    'preload' => array('log', 'rollbar'),
    ~~~

4. Set `RollbarErrorHandler` as error handler:
    ~~~
[php]
    'components' => array(
        // ...
        'errorHandler' => array(
            'class' => 'application.vendor.baibaratsky.yii-rollbar.RollbarErrorHandler',
            // ...
        ),
    ),
    ~~~

    You can also pass some additional rollbar options in the component config:
    `environment`, `branch`, `maxErrno`, `baseApiUrl`, etc.

    A good idea is to specify `environment` as:

    ~~~
[php]
    'environment' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'cli_' . php_uname('n'),
    ~~~

    You can specify alias of your project root directory for linking stack traces (`application` by default):
    ~~~
[php]
    'rootAlias' => 'root',
    ~~~


Rollbar Log Route
-----------------
You may want to collect your logs produced by `Yii::log()` in Rollbar. Put the following code in your config and enjoy:

[php] 'components' => array(

// ...
'log' => array(
    // ...
    'routes' => array(
        array(
            'class' => 'application.vendor.baibaratsky.yii-rollbar.RollbarLogRoute',
            'levels' => 'error, warning, info',

            // You may specify the name of the Rollbar Yii Component ('rollbar' by default)
            'rollbarComponentName' => 'rollbar',
        ),
    ),
),

), ~~~

0 0
1 follower
21 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Logging
Developed by: baibaratsky
Created on: Apr 27, 2015
Last updated: 8 years ago

Related Extensions