Skip to content

Lumen compatibility #10

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

Merged
merged 4 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,29 @@ You can install the package via composer:
composer require bilfeldt/laravel-http-client-logger
```

Optionally publish the config file with:
### Laravel

This package makes use of [Laravels package auto-discovery mechanism](https://medium.com/@taylorotwell/package-auto-discovery-in-laravel-5-5-ea9e3ab20518) so **there is no need to do any futher steps** - skip directly to the [usage](#usage) section below. If for some reason you wish to opt-out of package auto discovery, check [the Laravel Docs](https://laravel.com/docs/8.x/packages#opting-out-of-package-discovery) for more details.

### Lumen

NOTE: Lumen is **not** officially supported by this package. However, we are currently not aware of any incompatibilities.

If you use Lumen register the service provider in `bootstrap/app.php` like so:

```php
<?php
// bootstrap/app.php

$app->register(Bilfeldt\LaravelHttpClientLogger\LaravelHttpClientLoggerServiceProvider::class);

// If you want to use the Facades provided by the package
$app->withFacades();
```

### Config

Optionally in Laravel publish the config file with:
```bash
php artisan vendor:publish --provider="Bilfeldt\LaravelHttpClientLogger\LaravelHttpClientLoggerServiceProvider" --tag="laravel-http-client-logger-config"
```
Expand Down
3 changes: 2 additions & 1 deletion src/HttpLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Bilfeldt\LaravelHttpClientLogger;

use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -54,7 +55,7 @@ protected function getReplace(): array

protected function getFileName(): string
{
return (Arr::get($this->config, 'prefix_timestamp') ? now()->format(Arr::get($this->config, 'prefix_timestamp')) : '')
return (Arr::get($this->config, 'prefix_timestamp') ? Date::now()->format(Arr::get($this->config, 'prefix_timestamp')) : '')
.Arr::get($this->config, 'filename');
}

Expand Down
4 changes: 2 additions & 2 deletions src/LaravelHttpClientLoggerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function packageBooted()
) {
/** @var \Illuminate\Http\Client\PendingRequest $this */
return $this->withMiddleware((new LoggingMiddleware(
$logger ?? resolve(HttpLoggerInterface::class),
$filter ?? resolve(HttpLoggingFilterInterface::class)
$logger ?? app(HttpLoggerInterface::class),
$filter ?? app(HttpLoggingFilterInterface::class)
))->__invoke($context, $config));
});

Expand Down