bugsnag-laravel: Uncaught exception 'ReflectionException' with message 'Class bugsnag.logger does not exist'
My composer.json contains:
"bugsnag/bugsnag-laravel": "^2.0"
Into my config/app.php I have:
'providers' => [
...
Bugsnag\BugsnagLaravel\BugsnagServiceProvider::class,
...
]
and:
'aliases' => [
...
'Bugsnag' => Bugsnag\BugsnagLaravel\Facades\Bugsnag::class,
...
]
My AppServiceProvider.php contains:
use Illuminate\Contracts\Logging\Log;
use Psr\Log\LoggerInterface;
...
public function register()
{
$this->app->alias('bugsnag.logger', Log::class);
$this->app->alias('bugsnag.logger', LoggerInterface::class);
}
In my .env file I set BUGSNAG_API_KEY.
And I continously get the error (running php artisan serve or composer update, etc):
PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Class bugsnag.logger does not exist' in {my_project}/vendor/laravel/framework/src/Illuminate/Container/Container.php:734
Stack trace:
#0 {my_project}/vendor/laravel/framework/src/Illuminate/Container/Container.php(734): ReflectionClass->__construct('bugsnag.logger')
#1 {my_project}/vendor/laravel/framework/src/Illuminate/Container/Container.php(629): Illuminate\Container\Container->build('bugsnag.logger', Array)
#2 {my_project}/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(697): Illuminate\Container\Container->make('bugsnag.logger', Array)
#3 {my_project}/vendor/laravel/framework/src/Illuminate/Container/Container.php(849): Illuminate\Foundation\Application->make('Psr\\Log\\LoggerI...')
#4 {my_project}/vendor/laravel/framework/src/Illuminate/Container/Container.php(804): Illuminate\Container\Container->re in {my_project}/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 734
PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Class bugsnag.logger does not exist' in {my_project}/vendor/laravel/framework/src/Illuminate/Container/Container.php:734
Stack trace:
#0 {my_project}/vendor/laravel/framework/src/Illuminate/Container/Container.php(734): ReflectionClass->__construct('bugsnag.logger')
#1 {my_project}/vendor/laravel/framework/src/Illuminate/Container/Container.php(629): Illuminate\Container\Container->build('bugsnag.logger', Array)
#2 {my_project}/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(697): Illuminate\Container\Container->make('bugsnag.logger', Array)
#3 {my_project}/vendor/laravel/framework/src/Illuminate/Container/Container.php(849): Illuminate\Foundation\Application->make('Psr\\Log\\LoggerI...')
#4 {my_project}/vendor/laravel/framework/src/Illuminate/Container/Container.php(804): Illuminate\Container\Container->re in {my_project}/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 734
What am I doing wrong?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 19 (7 by maintainers)
Make sure you’ve put the bugsnag service provider above your app provider, and that you’ve run
php artisan config:cache.My
BugsnagServiceProviderhas always been before theAppServiceProvider, but after runningcomposer updatetoday, and getting the latest versionv2.14.1it broke with this error. The fix was to manually copy thebugsnag.phpconfig file from the vendor directory to theconfig/directory because evenartisangave the “Invalid API Key” error.As soon as I copied the config file, it started working magically.
Thanks for the information @russianryebread, I’ll have a look into why this is occurring for you.
I may be a little late, but perhaps this helps:
I accidentally loaded
after the AppServiceProvider (or in our case, BugsnagServiceProvider in App\Providers, since we have a slightly different app structure).
Make sure to have them loaded in correct order.
The exception gets thrown because of a different error and this error is hidden by the Bugsnag error as @GrahamCampbell mentioned. Best way to test whether this is the case in your case is to disable bugsnag temporarily and then run the command again and see whether you get the actual error. Then fix the error and enable bugsnag and you will find it fixed. Happened to me too.
I wonder if the command is crashing, and trying to log to bugsnag which is causing this error, which is hiding the real error?
I had the same invalid api key issue and was also fixed by
php artisan vendor:publish --provider="Bugsnag\BugsnagLaravel\BugsnagServiceProvider"You’re right, I put the service provider above app provider and it changes error:
(and I already have my
BUGSNAG_API_KEYin.envfile)I solved it publishing config with:
I see that the “service provider” order is suggested into this doc page but it isn’t into bugsnag dashboard integration instructions.
In all docs I see that isn’t required to publish config file, but for me nothing works without it.
Thanks for the support, regards