Skip to content

[4.0] Logger cannot be created with cached Laravel config #64

Closed
@jarnovanleeuwen

Description

@jarnovanleeuwen

When caching your Laravel configs using artisan config:cache the Rollbar logger breaks:

Unable to create configured logger. Using emergency logger. {"exception":"[object] (Illuminate\\Contracts\\Container\\BindingResolutionException(code: 0): Unresolvable dependency resolving [Parameter #0 [ <required> array $config ]] in class Rollbar\\RollbarLogger at vendor/laravel/framework/src/Illuminate/Container/Container.php:948)

The problem is in the stopping condition of the service provider: https://github.com/rollbar/rollbar-php-laravel/blob/master/src/RollbarServiceProvider.php#L93. getenv always returns NULL when a cached config exists (which is good). Therefore, the Rollbar token is received from the config using key logging.channels.rollbar.token. However, the access token is stored under a different config key: logging.channels.rollbar.access_token. The result is that stop() returns true and the Rollbar logger never gets registered in the service container.

A workaround is to also include the token key in the config array:

'rollbar' => [
    'driver' => 'monolog',
    'handler' => \Rollbar\Laravel\MonologHandler::class,
    'access_token' => env('ROLLBAR_TOKEN'),
    'token' => env('ROLLBAR_TOKEN'), // Temporarily due to Rollbar-Laravel bug.
    'level' => env('ROLLBAR_LEVEL')
]

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions