diff --git a/CHANGELOG.md b/CHANGELOG.md
index 18d2946..8e202c1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,34 @@ All notable changes to `laravel-http-client-logger` will be documented in this f
## Upgrade guides
+### 0.3.0 => 1.0.0
+
+This release flattens the configuration variables. It is suggested to republish the configuration after upgrading.
+
+- `filtering.always` is renamed to `filter_all`
+- `filtering.2xx` is renamed to `filter_2xx`
+- `filtering.3xx` is renamed to `filter_3xx`
+- `filtering.4xx` is renamed to `filter_4xx`
+- `filtering.5xx` is renamed to `filter_5xx`
+- `filtering.slow` is renamed to `filter_slow`
+- `log_to_channel.enabled` has been removed, instead logging to channel is enabled when a channel is provided
+- `log_to_channel.channel` is renamed to `channel`
+- `log_to_disk.enabled` has been removed, instead logging to disk is enabled when a disk is provided
+- `log_to_disk.disk` is renamed to `disk`
+- `log_to_disk.separate` is renamed to `disk_separate_files`
+- `log_to_disk.timestamp` is renamed to `prefix_timestamp`
+- `log_to_disk.filename` is renamed to `filename`
+
+The following environment variables have been renamed:
+- `HTTP_CLIENT_LOGGER_FILTERING_ALWAYS` is renamed to `HTTP_CLIENT_LOGGER_FILTER_ALL`
+- `HTTP_CLIENT_LOGGER_FILTERING_2XX` is renamed to `HTTP_CLIENT_LOGGER_FILTER_2XX`
+- `HTTP_CLIENT_LOGGER_FILTERING_3XX` is renamed to `HTTP_CLIENT_LOGGER_FILTER_3XX`
+- `HTTP_CLIENT_LOGGER_FILTERING_4XX` is renamed to `HTTP_CLIENT_LOGGER_FILTER_4XX`
+- `HTTP_CLIENT_LOGGER_FILTERING_5XX` is renamed to `HTTP_CLIENT_LOGGER_FILTER_5XX`
+- `HTTP_CLIENT_LOGGER_FILTERING_SLOW` is renamed to `HTTP_CLIENT_LOGGER_FILTER_SLOW`
+- `HTTP_CLIENT_LOGGER_CHANNEL_LOG_ENABLED` removed in favor of `HTTP_CLIENT_LOGGER_CHANNEL`
+- `HTTP_CLIENT_LOGGER_DISK_LOG_ENABLED` removed in favor of `HTTP_CLIENT_LOGGER_DISK`
+
### 0.2.0 => 0.3.0
This release includes breaking changes:
diff --git a/config/http-client-logger.php b/config/http-client-logger.php
index 12eccf7..89392f6 100644
--- a/config/http-client-logger.php
+++ b/config/http-client-logger.php
@@ -34,19 +34,17 @@
| that these settings are only used by the default filter.
|
*/
- 'filtering' => [
- 'always' => env('HTTP_CLIENT_LOGGER_FILTERING_ALWAYS', false),
+ 'filter_always' => env('HTTP_CLIENT_LOGGER_FILTER_ALL', false),
- '2xx' => env('HTTP_CLIENT_LOGGER_FILTERING_2XX', true),
+ 'filter_2xx' => env('HTTP_CLIENT_LOGGER_FILTER_2XX', true),
- '3xx' => env('HTTP_CLIENT_LOGGER_FILTERING_3XX', true),
+ 'filter_3xx' => env('HTTP_CLIENT_LOGGER_FILTER_3XX', true),
- '4xx' => env('HTTP_CLIENT_LOGGER_FILTERING_4XX', true),
+ 'filter_4xx' => env('HTTP_CLIENT_LOGGER_FILTER_4XX', true),
- '5xx' => env('HTTP_CLIENT_LOGGER_FILTERING_5XX', true),
+ 'filter_5xx' => env('HTTP_CLIENT_LOGGER_FILTER_5XX', true),
- 'slow' => env('HTTP_CLIENT_LOGGER_FILTERING_SLOW', 1.5), // Log requests that took longer than the setting (in sec)
- ],
+ 'filter_slow' => env('HTTP_CLIENT_LOGGER_FILTER_SLOW', 1.5), // Log requests that took longer than the setting (in sec)
/*
|--------------------------------------------------------------------------
@@ -62,32 +60,27 @@
/*
|--------------------------------------------------------------------------
- | Logger to channel
+ | Log to channel
|--------------------------------------------------------------------------
|
| These settings determine how to log request/responses to the Laravel log.
| Note that these settings are only used by the default logger.
+ | Set to false to disable the channel logging.
|
*/
- 'log_to_channel' => [
- 'enabled' => env('HTTP_CLIENT_LOGGER_CHANNEL_LOG_ENABLED', true),
- 'channel' => env('HTTP_CLIENT_LOGGER_CHANNEL'), // Uses the default log channel unless specified
- ],
+ 'channel' => env('HTTP_CLIENT_LOGGER_CHANNEL', 'default'),
/*
|--------------------------------------------------------------------------
- | Logger to disk
+ | Log to disk
|--------------------------------------------------------------------------
|
| These settings determine how to log request/responses to a flysystem disk.
| Note that these settings are only used by the default logger.
|
*/
- 'log_to_disk' => [
- 'enabled' => env('HTTP_CLIENT_LOGGER_DISK_LOG_ENABLED', true),
- 'disk' => env('HTTP_CLIENT_LOGGER_DISK'), // uses the default filesystem disk if none is specified
- 'separate' => true,
- 'timestamp' => 'Y-m-d-Hisu', // Leaving empty will remove the timestamp
- 'filename' => '',
- ],
+ 'disk' => env('HTTP_CLIENT_LOGGER_DISK', false),
+ 'disk_separate_files' => true,
+ 'prefix_timestamp' => 'Y-m-d-Hisu', // Leaving empty will remove the timestamp
+ 'filename' => '',
];
diff --git a/src/HttpLogger.php b/src/HttpLogger.php
index fed9b99..0042f77 100644
--- a/src/HttpLogger.php
+++ b/src/HttpLogger.php
@@ -36,14 +36,14 @@ public function log(
$this->response = $response;
$this->sec = $sec;
$this->context = $context;
- $this->config = array_replace_recursive(config('http-client-logger'), $config); // Note this does not work optimally!
+ $this->config = array_merge(config('http-client-logger'), $config);
- if (Arr::get($this->config, 'log_to_channel.enabled')) {
- $this->logToChannel(Arr::get($this->config, 'log_to_channel.channel') ?? config('logging.default'));
+ if (Arr::get($this->config, 'channel')) {
+ $this->logToChannel(($channel = Arr::get($this->config, 'channel')) == 'default' ? config('logging.default') : $channel);
}
- if (Arr::get($this->config, 'log_to_disk.enabled')) {
- $this->logToDisk(Arr::get($this->config, 'log_to_disk.disk') ?? config('filesystems.default'));
+ if (Arr::get($this->config, 'disk')) {
+ $this->logToDisk(($disk = Arr::get($this->config, 'disk')) == 'default' ? config('filesystems.default') : $disk);
}
}
@@ -54,8 +54,8 @@ protected function getReplace(): array
protected function getFileName(): string
{
- return (Arr::get($this->config, 'log_to_disk.timestamp') ? now()->format(Arr::get($this->config, 'log_to_disk.timestamp')) : '')
- .Arr::get($this->config, 'log_to_disk.filename');
+ return (Arr::get($this->config, 'prefix_timestamp') ? now()->format(Arr::get($this->config, 'prefix_timestamp')) : '')
+ .Arr::get($this->config, 'filename');
}
protected function getMessage(): string
@@ -82,7 +82,7 @@ protected function logToChannel(string $channel): void
protected function logToDisk(string $disk): void
{
- if (Arr::get($this->config, 'log_to_disk.separate')) {
+ if (Arr::get($this->config, 'disk_separate_files')) {
Storage::disk($disk)->put(
$this->getFileName().'-request'.Str::start($this->fileExt, '.'),
$this->psrMessageStringConverter->toString($this->request, $this->getReplace())
diff --git a/src/HttpLoggingFilter.php b/src/HttpLoggingFilter.php
index 029ec3d..a88b8e5 100644
--- a/src/HttpLoggingFilter.php
+++ b/src/HttpLoggingFilter.php
@@ -18,27 +18,27 @@ public function shouldLog(
return false;
}
- if (config('http-client-logger.filtering.always')) {
+ if (config('http-client-logger.filter_always')) {
return true;
}
- if (config('http-client-logger.filtering.2xx') && $response->getStatusCode() >= 200 && $response->getStatusCode() < 300) {
+ if (config('http-client-logger.filter_2xx') && $response->getStatusCode() >= 200 && $response->getStatusCode() < 300) {
return true;
}
- if (config('http-client-logger.filtering.3xx') && $response->getStatusCode() >= 300 && $response->getStatusCode() < 400) {
+ if (config('http-client-logger.filter_3xx') && $response->getStatusCode() >= 300 && $response->getStatusCode() < 400) {
return true;
}
- if (config('http-client-logger.filtering.4xx') && $response->getStatusCode() >= 400 && $response->getStatusCode() < 500) {
+ if (config('http-client-logger.filter_4xx') && $response->getStatusCode() >= 400 && $response->getStatusCode() < 500) {
return true;
}
- if (config('http-client-logger.filtering.5xx') && $response->getStatusCode() >= 500 && $response->getStatusCode() < 600) {
+ if (config('http-client-logger.filter_5xx') && $response->getStatusCode() >= 500 && $response->getStatusCode() < 600) {
return true;
}
- if (config('http-client-logger.filtering.slow') < $sec) {
+ if (config('http-client-logger.filter_slow') < $sec) {
return true;
}
diff --git a/tests/HttpLoggingFilterTest.php b/tests/HttpLoggingFilterTest.php
index 9adc36a..d61edb9 100644
--- a/tests/HttpLoggingFilterTest.php
+++ b/tests/HttpLoggingFilterTest.php
@@ -19,7 +19,7 @@ public function setUp(): void
public function test_filter_log_2xx()
{
- config(['http-client-logger.filtering.2xx' => true]);
+ config(['http-client-logger.filter_2xx' => true]);
$this->assertTrue($this->filter->shouldLog(
new Request('GET', '/'),
@@ -27,7 +27,7 @@ public function test_filter_log_2xx()
0
));
- config(['http-client-logger.filtering.2xx' => false]);
+ config(['http-client-logger.filter_2xx' => false]);
$this->assertFalse($this->filter->shouldLog(
new Request('GET', '/'),
@@ -38,7 +38,7 @@ public function test_filter_log_2xx()
public function test_filter_log_3xx()
{
- config(['http-client-logger.filtering.3xx' => true]);
+ config(['http-client-logger.filter_3xx' => true]);
$this->assertTrue($this->filter->shouldLog(
new Request('GET', '/'),
@@ -46,7 +46,7 @@ public function test_filter_log_3xx()
0
));
- config(['http-client-logger.filtering.3xx' => false]);
+ config(['http-client-logger.filter_3xx' => false]);
$this->assertFalse($this->filter->shouldLog(
new Request('GET', '/'),
@@ -57,7 +57,7 @@ public function test_filter_log_3xx()
public function test_filter_log_4xx()
{
- config(['http-client-logger.filtering.4xx' => true]);
+ config(['http-client-logger.filter_4xx' => true]);
$this->assertTrue($this->filter->shouldLog(
new Request('GET', '/'),
@@ -65,7 +65,7 @@ public function test_filter_log_4xx()
0
));
- config(['http-client-logger.filtering.4xx' => false]);
+ config(['http-client-logger.filter_4xx' => false]);
$this->assertFalse($this->filter->shouldLog(
new Request('GET', '/'),
@@ -76,7 +76,7 @@ public function test_filter_log_4xx()
public function test_filter_log_5xx()
{
- config(['http-client-logger.filtering.5xx' => true]);
+ config(['http-client-logger.filter_5xx' => true]);
$this->assertTrue($this->filter->shouldLog(
new Request('GET', '/'),
@@ -84,7 +84,7 @@ public function test_filter_log_5xx()
0
));
- config(['http-client-logger.filtering.5xx' => false]);
+ config(['http-client-logger.filter_5xx' => false]);
$this->assertFalse($this->filter->shouldLog(
new Request('GET', '/'),
@@ -95,8 +95,8 @@ public function test_filter_log_5xx()
public function test_filter_log_slow()
{
- config(['http-client-logger.filtering.2xx' => false]);
- config(['http-client-logger.filtering.slow' => 1.5]);
+ config(['http-client-logger.filter_2xx' => false]);
+ config(['http-client-logger.filter_slow' => 1.5]);
$this->assertFalse($this->filter->shouldLog(
new Request('GET', '/'),
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 5767e87..aab38bc 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -13,11 +13,11 @@ public function setUp(): void
parent::setUp();
- config()->set('http-client-logger.filtering.2xx', true);
- config()->set('http-client-logger.filtering.3xx', true);
- config()->set('http-client-logger.filtering.4xx', true);
- config()->set('http-client-logger.filtering.5xx', true);
- config()->set('http-client-logger.filtering.slow', true);
+ config()->set('http-client-logger.filter_2xx', true);
+ config()->set('http-client-logger.filter_3xx', true);
+ config()->set('http-client-logger.filter_4xx', true);
+ config()->set('http-client-logger.filter_5xx', true);
+ config()->set('http-client-logger.filter_slow', true);
}
protected function getPackageProviders($app)