rollbar / rollbar-php-laravel

Rollbar error monitoring integration for Laravel projects
https://docs.rollbar.com/docs/laravel
140 stars 39 forks source link

'handler' config conflict #85

Closed Hornet-Wing closed 3 years ago

Hornet-Wing commented 5 years ago

I've been looking at using rollbar-agent to do the actual sending to Rollbar. However, it is not possible to currently configure it in the logging config file as the handler key is used by natively by Laravel (5.8). So When I attempt to use the following config:

'rollbar' => [
    'driver' => 'monolog',
    'level' => 'debug',
    'handler' => 'agent',
    'agent_log_location' => storage_path('logs/rollbar'),
    'access_token' => env('ROLLBAR_TOKEN'),
],

I get the following error:

[2019-07-26 16:35:20] laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (InvalidArgumentException(code: 0): agent must be an instance of Monolog\\Handler\\HandlerInterface at laravel-project\\vendor\\laravel\\framework\\src\\Illuminate\\Log\\LogManager.php:328)

So I was able to validate my suspicions by reverting the handler back to using Rollbar\Laravel\MonologHandler::class and editing $config in RollbarServiceProvider.php to overwrite the handler key just before it gets passed into Rollbar::init. This made everything work and Rollbar started logging to the folder.

So, either the the key for the handler (used by Rollbar) needs to be changed or a better solution would be to nest the Rollbar specific settings to prevent conflict in the future. For example:

Altered key:

'rollbar' => [
    'driver' => 'monolog',
    'handler' => Rollbar\Laravel\MonologHandler::class,
    'level' => 'debug',
    'rollbar_handler' => 'agent',
    'agent_log_location' => storage_path('logs/rollbar'),
    'access_token' => env('ROLLBAR_TOKEN'),
],

Nested settings:

'rollbar' => [
    'driver' => 'monolog',
    'handler' => Rollbar\Laravel\MonologHandler::class,
    'level' => 'debug',
    'rollbar_config' => [
        'access_token' => env('ROLLBAR_TOKEN'),
        'handler' => 'agent',
        'agent_log_location' => storage_path('logs/rollbar'),
    ]
],
Lukasz93P commented 3 years ago

@bishopb @brianr @waltjones Hi, can you finally fix this? This issue is about a year old and this bug still exists - can you do something with that?

bishopb commented 3 years ago

Thank you for reporting this issue. It's fixed by Pull Request #109. To use rollbar-agent, set handler to Rollbar\Laravel\AgentHandler::class.

bishopb commented 3 years ago

This is now available as of v7.1.0-RC1.