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

[10.x] Configure Stripe logger #790

Merged
merged 4 commits into from
Sep 30, 2019
Merged

Conversation

sebdesign
Copy link
Contributor

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:

'logger' => 'default',

3. Or by calling Cashier::useLogger() in the register method of a service provider:

Cashier::useLogger('default');

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');
```
Copy link
Member

@driesvints driesvints left a 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.

src/Cashier.php Outdated Show resolved Hide resolved
tests/Unit/LoggerTest.php Outdated Show resolved Hide resolved
src/Logger.php Show resolved Hide resolved
@driesvints driesvints changed the title Configure Stripe logger [10.x] Configure Stripe logger Sep 26, 2019
@sebdesign
Copy link
Contributor Author

sebdesign commented Sep 26, 2019 via email

@driesvints
Copy link
Member

@sebdesign took the liberty to update some stuff already. We'll get this merged in soon

@sebdesign
Copy link
Contributor Author

@driesvints thanks for pitching in! I just saw the changes you made, all looks good!

@sebdesign
Copy link
Contributor Author

@driesvints Actually I had another thought, since we can have logging channel now, what that make sense to report our exceptions (in Cashier\Exception) to the specified channel?

E.g. the SubscriptionUpdateFailure would have a method like this?

public function report()
{
    Log::channel(config('cashier.logger'))->error($this->getMessage(), [
        'exception' => $this,
    ]);
}

@driesvints
Copy link
Member

Think it's still best to let those exceptions be handled by the user

@taylorotwell taylorotwell merged commit 006ab8b into laravel:10.0 Sep 30, 2019
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

Successfully merging this pull request may close these issues.

3 participants