kreait / laravel-firebase

A Laravel package for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
994 stars 163 forks source link

Error in debug mode #86

Closed jacob418 closed 3 years ago

jacob418 commented 3 years ago

When using the FIREBASE_ENABLE_DEBUG=true setting in the .env file i ran into an error: Kreait\\Firebase\\Factory::withEnabledDebug without a Psr\\Log\\LoggerInterface is deprecated.

I found out that i can fix the problem by replacing the following line:

Kreait\Laravel\Firebase\FirebaseProjectManager (Line 88)

            $factory = $factory->withEnabledDebug();

with this:

            $factory = $factory->withEnabledDebug(app('log'));

However, changing contents of the vendor folder is nothing I consider a good practice, even though its only in development.

EDIT: I also noticed, that the debug-log is generated via the info method. Since its called 'debug'-log I'd expect to read debug here.

jeromegamez commented 3 years ago

While looking into this (and running into trouble because the tests don't work in PHP 8.0 😅), I noticed that I deprecated this specific way of enabling the debug mode (https://github.com/kreait/laravel-firebase/blob/f95cda43a2515f1d18cc0783c22f54ca51e0d2ba/config/firebase.php#L180)

The only thing this method did was enabling the debug mode in Guzzle which only spills out debug information to STDOUT.

Long story short: $factory->withEnabledDebug(app('log')) is effectively the same as specifying a log channel in the firebase.logging.http_debug_log_channel at https://github.com/kreait/laravel-firebase/blob/f95cda43a2515f1d18cc0783c22f54ca51e0d2ba/config/firebase.php#L151

Less long story shorter: please don't use the debug option, but instead use the logging options in config/firebase.php, either by specifying them in the file or via the given environment variables:

https://github.com/kreait/laravel-firebase/blob/f95cda43a2515f1d18cc0783c22f54ca51e0d2ba/config/firebase.php#L135-L154

Although it's called debug-log, the info and notice differentiation is useful to be able to distinguish successful from unsuccessful requests - if you don't want to "pollute" your other logs, please use a distinct log channel only for debugging Firebase related HTTP requests 🤞