soyhuce/laravel-rollbar

Rollbar wrapper for Laravel

0.1.1 2022-01-07 14:55 UTC

This package is auto-updated.

Last update: 2024-11-07 21:03:33 UTC


README

alt text

Rollbar wrapper for Laravel

Installation

You can install the package via composer:

composer require soyhuce/laravel-rollbar

You can then add rollbar configuration in your config/logging.php

return [
    //...

    'channels' => [
        'rollbar' => [
            'driver' => 'monolog',
            'handler' => \Soyhuce\LaravelRollbar\LaravelRollbarHandler::class,
            'level' => env('LOG_LEVEL', 'error'),
            'access_token' => env('ROLLBAR_SERVER_KEY'),
        ],
    ],
];

You can add the configurations you need. See the Rollbar documentation for more information.

Customizing current user resolution

You can customize the current user resolution with \Soyhuce\LaravelRollbar\Facades\Rollbar::resolveAuthenticatedUserUsing(). You may want to add this in a service provider (for example AppServiceProvider).

\Soyhuce\LaravelRollbar\Facades\Rollbar::resolveAuthenticatedUserUsing(function (): array {
    $user = auth()->user();
    
    if ($user === null) {
        return [];
    }
    
    return [
        'id' => (string) $user->id, // id must be a string
        'role' => $user->role->label,
    ];
});

A default user resolver is provided in this package.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

License

The MIT License (MIT). Please see License File for more information.