Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaravelLogger references class that no longer exists (Illuminate\Contracts\Logging\Log) in Laravel 5.6+ #546

Open
justincdotme opened this issue Dec 11, 2024 · 7 comments

Comments

@justincdotme
Copy link

Expected behavior

composer update doesn't produce the error laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (ReflectionException(code: 0): Class 'Illuminate\\Contracts\\Logging\\Log' not found

Observed behavior

The class Bugsnag\BugsnagLaravel\LaravelLogger imports this class on line 8 https://github.com/bugsnag/bugsnag-laravel/blob/master/src/LaravelLogger.php#L8 and causes an error to be written to the log if composer update is run while the .env includes a reference to the bugsnag log channel in the LOG_STACK or if it's referenced in any of the log channels in that file in Laravel 5.6+

Steps to reproduce

  1. Follow the installation steps listed on this page in a Laravel 5.6 application. In this case I am using Laravel 11. https://docs.bugsnag.com/platforms/php/laravel/
  2. Add a logging channel for bugsnag to config/logging.php
  3. Reference that channel in .env
  4. Run composer update
  5. Observe the error in the log file. In my case it was in storage/logs/laravel.log.

Version

2.28.0

Additional information

The Laravel team removed the Illuminate\Contracts\Logging\Log class in Laravel 5.6 because it was a duplicate of Psr\Log\LoggerInterface. This was mentioned in the Laravel 5.6 upgrade guide: https://laravel.com/docs/5.6/upgrade

I'm not sure that the reference to the Psr\Log\LoggerInterface is even needed in Bugsnag\BugsnagLaravel\LaravelLogger since that class ultimately extends Psr\Log\AbstractLogger which already implements the correct interface.

Can't comment on Issues?

Some users have been unable to comment on Github issues when an adblocker extension is enabled.
We recommend temporarily disabling the extension, or if that fails, contacting [email protected].

@GrahamCampbell
Copy link
Contributor

This is a non-issue. That class only exists to support older Laravel versions. On newer Laravel versions, the entire class is not used at all.

@GrahamCampbell
Copy link
Contributor

@justincdotme
Copy link
Author

@GrahamCampbell I guess I'm not following why it's not an issue. Log::class on line 346 of that service provider is Illuminate\Contracts\Logging\Log but the installation instructions state to add that service provider to the $providers array in bootstrap/providers.php.

@GrahamCampbell
Copy link
Contributor

That line checks to see if the class exists, so that we can do the correct thing on both older and newer Laravel.

@justincdotme
Copy link
Author

I see, is there a clean way to prevent that error from appearing in the laravel.log then?

@GrahamCampbell
Copy link
Contributor

Are you using the latest version of this package, or a version before that interface_exists check was added?

@justincdotme
Copy link
Author

I'm using v2.28.0. The interface_exists(Log::class) check is present on 346 in that file. This is on PHP 8.2.25.

Upon further investigation, it looks like this might be caused by a combination of the import of the old class and the way that the barryvdh/laravel-ide-helper package handles autoloading: https://github.com/barryvdh/laravel-ide-helper/blob/master/src/Console/MetaCommand.php#L155-L162

Could the Bugsnag package just check the value of Illuminate\Foundation\Application::VERSION instead of checking if the interface exists or is it not that simple?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants