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)

Most upvoted comments

Make sure you’ve put the bugsnag service provider above your app provider, and that you’ve run php artisan config:cache.

My BugsnagServiceProvider has always been before the AppServiceProvider, but after running composer update today, and getting the latest version v2.14.1 it broke with this error. The fix was to manually copy the bugsnag.php config file from the vendor directory to the config/ directory because even artisan gave the “Invalid API Key” error.

screen shot 2018-03-20 at 4 57 18 pm

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

Bugsnag\BugsnagLaravel\BugsnagServiceProvider::class,

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:

 Uncaught exception 'InvalidArgumentException' with message 'Invalid API key'

(and I already have my BUGSNAG_API_KEY in .env file)

I solved it publishing config with:

php artisan vendor:publish --provider="Bugsnag\BugsnagLaravel\BugsnagServiceProvider"

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