-
Notifications
You must be signed in to change notification settings - Fork 681
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
[10.x] Configure Stripe logger #790
Conversation
Allow users to configure the Stripe library logger using Laravel's logging channels. By default the Stripe library uses a subset of the PSR-3 logger interface to writes log messages using `error_log`. This feature gives users the ability to use Laravel's logging channels instead, by decorating them in a `Laravel\Cashier\Logger` class, which implements Stripe's logging interface. For more advanced cases, the decorator can accept any PSR-3 implementation. We can define the desired logging channel name in 3 ways: 1. Using the `CASHIER_LOGGER` variable in the .env file. ``` CASHIER_LOGGER=default ``` 2. Otherwise the `cashier.logger` configuration value can be overriden in the published `cashier.php`: ```php 'logger' => 'default', ``` 3. Or by calling `Cashier::useLogger()` in the `register` method of a service provider: ```php Cashier::useLogger('default'); ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this! Thanks for sending this in. Some feedback and also make sure the StyleCI failures are fixed.
Thank you for your feedback! I'll do these changes tonight.
Le jeu. 26 sept. 2019 à 11:06, Dries Vints <notifications@github.com> a
écrit :
… ***@***.**** requested changes on this pull request.
I like this! Thanks for sending this in. Some feedback and also make sure
the StyleCI failures are fixed.
------------------------------
In src/Cashier.php
<#790 (comment)>:
> @@ -114,4 +121,17 @@ public static function ignoreRoutes()
return new static;
}
+
+ /**
+ * Configure Stripe to use a logging channel.
+ *
+ * @param string|null $logger
+ * @return static
+ */
+ public static function useLogger($logger)
No need to have two ways of setting the logger so let's remove the static
method and property here and only use the config.
------------------------------
In tests/Unit/LoggerTest.php
<#790 (comment)>:
> @@ -0,0 +1,99 @@
+<?php
+
+namespace Laravel\Cashier\Tests\Unit;
This test will need to be moved to the Integration suite because the
framework is bootstrapped.
------------------------------
In src/Logger.php
<#790 (comment)>:
> @@ -0,0 +1,27 @@
+<?php
+
+namespace Laravel\Cashier;
+
+use Psr\Log\LoggerInterface;
+use Stripe\Util\LoggerInterface as StripeLogger;
+
+class Logger implements StripeLogger
+{
+ /**
+ * @var \Psr\Log\LoggerInterface
+ */
+ protected $logger;
+
+ public function __construct(LoggerInterface $logger)
Add a DocBlock to the constructor like other classes.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#790>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAFC4CFWDBIPRLHWTHIYXHLQLRUPTANCNFSM4I2TGEFA>
.
|
@sebdesign took the liberty to update some stuff already. We'll get this merged in soon |
@driesvints thanks for pitching in! I just saw the changes you made, all looks good! |
@driesvints Actually I had another thought, since we can have logging channel now, what that make sense to report our exceptions (in E.g. the public function report()
{
Log::channel(config('cashier.logger'))->error($this->getMessage(), [
'exception' => $this,
]);
} |
Think it's still best to let those exceptions be handled by the user |
Allow users to configure the Stripe library logger using Laravel's logging channels.
By default the Stripe library uses a subset of the PSR-3 logger interface to writes log messages using
error_log
.This feature gives users the ability to use Laravel's logging channels instead, by decorating them in a
Laravel\Cashier\Logger
class, which implements Stripe's logging interface. For more advanced cases, the decorator can accept any PSR-3 implementation.We can define the desired logging channel name in 3 ways:
1. Using the
CASHIER_LOGGER
variable in the .env file.2. Otherwise the
cashier.logger
configuration value can be overriden in the publishedcashier.php
:3. Or by calling
Cashier::useLogger()
in theregister
method of a service provider: