PHP code example of oaksoftwaredev / yii2-rollbar

1. Go to this page and download the library: Download oaksoftwaredev/yii2-rollbar library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

oaksoftwaredev / yii2-rollbar example snippets


'components' => [
    'rollbar' => [
        'class' => 'oaksoftwaredev\yii2\rollbar\RollbarLoader',
        'config' => [
            'environment' => '{your_environment}',
            'access_token' => '{rollber_access_token}',
            'send_message_trace' => true,
            'ore ($toLog, [
                   ['yii\web\HttpException', 'statusCode' => [400, 404]], // check properties
                ]);
            },
        ],
    ],
]

'components' => [
    'errorHandler' => [
        'class' => 'oaksoftwaredev\yii2\rollbar\handlers\WebErrorHandler',
    ],
],

'components' => [
    'errorHandler' => [
        'class' => 'oaksoftwaredev\yii2\rollbar\handlers\ConsoleErrorHandler',
    ],
],

use oaksoftwaredev\yii2\rollbar\PayloadInterface;
 
class SomeException extends \Exception implements PayloadInterface
{
    public function rollbarPayload()
    {
        return ['foo' => 'bar'];
    }
}

'components' => [
    'log' => [
        'targets' => [
            [
                'class' => 'oaksoftwaredev\yii2\rollbar\RollbarTarget',
                'levels' => ['error', 'warning', 'info'], // Log levels you want to appear in Rollbar             
                'categories' => ['application'],
            ],
        ],
    ],
],

'assetManager' => [
    'bundles' => [
        'oaksoftwaredev\yii2\rollbar\RollbarAsset' => [
            // Rollbar configuration
            'config' => [
                'accessToken' => '{token}',
                'payload' => [
                    'environment' => '{environment}',                    
                ],
            ],
            // metrics to add to payload, called when the asset is registered
            'payload' => function () {
                return [
                    'person' => [
                        'id' => \Yii::$app->has('user') ? (string) \Yii::$app->user->id : null,
                        'username' => \Yii::$app->has('user') && ! \Yii::$app->user->isGuest ? \Yii::$app->user->identity->username : null,
                    ],
                ];
            },
        ],
    ],
],

$ php composer.phar