diff --git a/README.md b/README.md index 569ebf9..603c500 100644 --- a/README.md +++ b/README.md @@ -103,21 +103,6 @@ Scrubber::processMessage([ Scrubber::processMessage(''); // **redacted** ``` -## Log Channel Opt-in - -This package provides you the ability to define through the configuration file what channels you want to scrub -specifically. By default, this package ships with a wildcard value and opts in to scrub all the log channels -in your application. - -### Defining Log Channel Opt-in -To opt in to one or more channels, list the channel(s) name into the `tap_channels` array in the config. - -```php -'tap_channels' => [ - 'single', - 'papertrail' -] -``` ## Log Channel Opt-in @@ -136,6 +121,11 @@ To opt in to one or more channels, list the channel(s) name into the `tap_channe ] ``` +To disable tap logging functionality and use the package independently and not tap your Laravel application logging, modify the config file by setting the tap_channels field as follows: +```php +'tap_channels' => false +``` + ## Regex Class Opt-in You have the ability through the configuration file to define what regex classes you want loaded into the application diff --git a/composer.lock b/composer.lock index 176a18d..10e8961 100644 --- a/composer.lock +++ b/composer.lock @@ -983,12 +983,12 @@ "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "ac3fecd58ba88858d7560e99643a5790cfb5ca6c" + "reference": "973b54ed201cdf1ec820699831e39189327ae17e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/ac3fecd58ba88858d7560e99643a5790cfb5ca6c", - "reference": "ac3fecd58ba88858d7560e99643a5790cfb5ca6c", + "url": "https://api.github.com/repos/laravel/framework/zipball/973b54ed201cdf1ec820699831e39189327ae17e", + "reference": "973b54ed201cdf1ec820699831e39189327ae17e", "shasum": "" }, "require": { @@ -1176,7 +1176,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2023-06-20T19:46:51+00:00" + "time": "2023-06-23T13:32:04+00:00" }, { "name": "laravel/serializable-closure", @@ -1245,12 +1245,12 @@ "source": { "type": "git", "url": "https://github.com/thephpleague/commonmark.git", - "reference": "23a79e419dae0e650b3378b2e7845f54ed0f6659" + "reference": "4aec9f51ec30efd59164d2a2bd649171b8893c05" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/23a79e419dae0e650b3378b2e7845f54ed0f6659", - "reference": "23a79e419dae0e650b3378b2e7845f54ed0f6659", + "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/4aec9f51ec30efd59164d2a2bd649171b8893c05", + "reference": "4aec9f51ec30efd59164d2a2bd649171b8893c05", "shasum": "" }, "require": { @@ -1343,7 +1343,7 @@ "type": "tidelift" } ], - "time": "2023-05-26T15:15:49+00:00" + "time": "2023-06-23T16:17:35+00:00" }, { "name": "league/config", @@ -1640,12 +1640,12 @@ "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "1fd8e8c2c75ab9d1e2cf8227cb078815b249ca75" + "reference": "e2392369686d420ca32df3803de28b5d6f76867d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/1fd8e8c2c75ab9d1e2cf8227cb078815b249ca75", - "reference": "1fd8e8c2c75ab9d1e2cf8227cb078815b249ca75", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/e2392369686d420ca32df3803de28b5d6f76867d", + "reference": "e2392369686d420ca32df3803de28b5d6f76867d", "shasum": "" }, "require": { @@ -1722,7 +1722,7 @@ ], "support": { "issues": "https://github.com/Seldaek/monolog/issues", - "source": "https://github.com/Seldaek/monolog/tree/main" + "source": "https://github.com/Seldaek/monolog/tree/3.4.0" }, "funding": [ { @@ -1734,7 +1734,7 @@ "type": "tidelift" } ], - "time": "2023-06-20T14:42:38+00:00" + "time": "2023-06-21T08:46:11+00:00" }, { "name": "nesbot/carbon", @@ -3274,12 +3274,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "5dd32046e23f52038ac674ca270afd48d5cdb65a" + "reference": "a9cb76a20ead0cd453f8574b3cd5523a9dbfad68" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/5dd32046e23f52038ac674ca270afd48d5cdb65a", - "reference": "5dd32046e23f52038ac674ca270afd48d5cdb65a", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/a9cb76a20ead0cd453f8574b3cd5523a9dbfad68", + "reference": "a9cb76a20ead0cd453f8574b3cd5523a9dbfad68", "shasum": "" }, "require": { @@ -3343,7 +3343,7 @@ "type": "tidelift" } ], - "time": "2023-06-04T14:51:04+00:00" + "time": "2023-06-21T12:09:04+00:00" }, { "name": "symfony/http-kernel", @@ -3351,12 +3351,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "45516b6d06c4696468c1bf6eae8afaf3752e9a8c" + "reference": "50f99455081726013086580caf10b6690d6cb255" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/45516b6d06c4696468c1bf6eae8afaf3752e9a8c", - "reference": "45516b6d06c4696468c1bf6eae8afaf3752e9a8c", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/50f99455081726013086580caf10b6690d6cb255", + "reference": "50f99455081726013086580caf10b6690d6cb255", "shasum": "" }, "require": { @@ -3456,7 +3456,7 @@ "type": "tidelift" } ], - "time": "2023-06-20T15:03:27+00:00" + "time": "2023-06-21T12:09:04+00:00" }, { "name": "symfony/mailer", @@ -4930,12 +4930,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "30610109879daf79e6042430d56346681801dfcd" + "reference": "4415fa3b61b7259aca2bf925ab97c03865072ac5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/30610109879daf79e6042430d56346681801dfcd", - "reference": "30610109879daf79e6042430d56346681801dfcd", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/4415fa3b61b7259aca2bf925ab97c03865072ac5", + "reference": "4415fa3b61b7259aca2bf925ab97c03865072ac5", "shasum": "" }, "require": { @@ -5004,7 +5004,7 @@ "type": "tidelift" } ], - "time": "2023-06-01T08:31:05+00:00" + "time": "2023-06-21T12:09:04+00:00" }, { "name": "tijsverkoyen/css-to-inline-styles", @@ -5794,12 +5794,12 @@ "source": { "type": "git", "url": "https://github.com/orchestral/testbench-core.git", - "reference": "5f035c104673542909d6e4912202aa357419aa69" + "reference": "c9c36e8ef9a8b91cbcc85f629be5ff3670133737" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/orchestral/testbench-core/zipball/5f035c104673542909d6e4912202aa357419aa69", - "reference": "5f035c104673542909d6e4912202aa357419aa69", + "url": "https://api.github.com/repos/orchestral/testbench-core/zipball/c9c36e8ef9a8b91cbcc85f629be5ff3670133737", + "reference": "c9c36e8ef9a8b91cbcc85f629be5ff3670133737", "shasum": "" }, "require": { @@ -5868,7 +5868,7 @@ "issues": "https://github.com/orchestral/testbench/issues", "source": "https://github.com/orchestral/testbench-core" }, - "time": "2023-06-20T03:32:57+00:00" + "time": "2023-06-22T05:28:42+00:00" }, { "name": "phar-io/manifest", @@ -6314,12 +6314,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "26ad1b9e87ef46650e951945c7d48659788f0950" + "reference": "b42903714098f586163dbef4c427f40482341273" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/26ad1b9e87ef46650e951945c7d48659788f0950", - "reference": "26ad1b9e87ef46650e951945c7d48659788f0950", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b42903714098f586163dbef4c427f40482341273", + "reference": "b42903714098f586163dbef4c427f40482341273", "shasum": "" }, "require": { @@ -6409,7 +6409,7 @@ "type": "tidelift" } ], - "time": "2023-06-19T06:33:11+00:00" + "time": "2023-06-23T06:13:06+00:00" }, { "name": "pimple/pimple", @@ -7492,16 +7492,16 @@ }, { "name": "spatie/laravel-ray", - "version": "1.32.4", + "version": "1.32.5", "source": { "type": "git", "url": "https://github.com/spatie/laravel-ray.git", - "reference": "2274653f0a90dd87fbb887437be1c1ea1388a47c" + "reference": "288f30c94c9725dfd78d8a1b82b230521f4d697e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-ray/zipball/2274653f0a90dd87fbb887437be1c1ea1388a47c", - "reference": "2274653f0a90dd87fbb887437be1c1ea1388a47c", + "url": "https://api.github.com/repos/spatie/laravel-ray/zipball/288f30c94c9725dfd78d8a1b82b230521f4d697e", + "reference": "288f30c94c9725dfd78d8a1b82b230521f4d697e", "shasum": "" }, "require": { @@ -7561,7 +7561,7 @@ ], "support": { "issues": "https://github.com/spatie/laravel-ray/issues", - "source": "https://github.com/spatie/laravel-ray/tree/1.32.4" + "source": "https://github.com/spatie/laravel-ray/tree/1.32.5" }, "funding": [ { @@ -7573,7 +7573,7 @@ "type": "other" } ], - "time": "2023-03-23T08:04:54+00:00" + "time": "2023-06-23T07:04:32+00:00" }, { "name": "spatie/macroable", diff --git a/config/scrubber.php b/config/scrubber.php index db7e926..3730e2c 100644 --- a/config/scrubber.php +++ b/config/scrubber.php @@ -17,5 +17,5 @@ ], ], 'regex_loader' => ['*'], - 'tap_channels' => ['*'], + 'tap_channels' => false, ]; diff --git a/src/ScrubberServiceProvider.php b/src/ScrubberServiceProvider.php index 353421b..e86f9c3 100644 --- a/src/ScrubberServiceProvider.php +++ b/src/ScrubberServiceProvider.php @@ -17,7 +17,6 @@ use YorCreative\Scrubber\Strategies\RegexLoader\Loaders\SpecificExtendedRegex; use YorCreative\Scrubber\Strategies\RegexLoader\Loaders\WildcardExtendedRegex; use YorCreative\Scrubber\Strategies\RegexLoader\RegexLoaderStrategy; -use YorCreative\Scrubber\Strategies\TapLoader\Loaders\DefaultChannels; use YorCreative\Scrubber\Strategies\TapLoader\Loaders\MultipleChannel; use YorCreative\Scrubber\Strategies\TapLoader\Loaders\SpecificChannel; use YorCreative\Scrubber\Strategies\TapLoader\Loaders\WildCardChannel; @@ -71,7 +70,6 @@ public function boot() $tapLoaderStrategy->setLoader(new WildCardChannel()); $tapLoaderStrategy->setLoader(new SpecificChannel()); $tapLoaderStrategy->setLoader(new MultipleChannel()); - $tapLoaderStrategy->setLoader(new DefaultChannels()); return $tapLoaderStrategy; }); diff --git a/src/Strategies/TapLoader/Loaders/DefaultChannels.php b/src/Strategies/TapLoader/Loaders/DefaultChannels.php deleted file mode 100644 index 3504a96..0000000 --- a/src/Strategies/TapLoader/Loaders/DefaultChannels.php +++ /dev/null @@ -1,25 +0,0 @@ -get('logging.channels'); - - foreach ($channels as $key => $channel) { - $config->set("logging.channels.$key.tap", [ - ScrubberTap::class, - ]); - } - } -} diff --git a/src/Strategies/TapLoader/Loaders/MultipleChannel.php b/src/Strategies/TapLoader/Loaders/MultipleChannel.php index cd2d0d1..675ad1b 100644 --- a/src/Strategies/TapLoader/Loaders/MultipleChannel.php +++ b/src/Strategies/TapLoader/Loaders/MultipleChannel.php @@ -12,7 +12,8 @@ class MultipleChannel implements TapLoaderInterface public function canLoad(): bool { $channels = Config::get('scrubber.tap_channels'); - if (! $channels) { + + if (! $channels || ! is_array($channels)) { return false; } diff --git a/src/Strategies/TapLoader/Loaders/SpecificChannel.php b/src/Strategies/TapLoader/Loaders/SpecificChannel.php index 6e3a128..6410651 100644 --- a/src/Strategies/TapLoader/Loaders/SpecificChannel.php +++ b/src/Strategies/TapLoader/Loaders/SpecificChannel.php @@ -12,7 +12,8 @@ class SpecificChannel implements TapLoaderInterface public function canLoad(): bool { $channels = Config::get('scrubber.tap_channels'); - if (! $channels) { + + if (! $channels || ! is_array($channels)) { return false; } diff --git a/src/Strategies/TapLoader/Loaders/WildCardChannel.php b/src/Strategies/TapLoader/Loaders/WildCardChannel.php index 8529718..976ea4e 100644 --- a/src/Strategies/TapLoader/Loaders/WildCardChannel.php +++ b/src/Strategies/TapLoader/Loaders/WildCardChannel.php @@ -12,7 +12,8 @@ class WildCardChannel implements TapLoaderInterface public function canLoad(): bool { $channels = Config::get('scrubber.tap_channels'); - if (! $channels) { + + if (! $channels || ! is_array($channels)) { return false; } diff --git a/tests/Unit/Strategies/TapLoaderStrategyTest.php b/tests/Unit/Strategies/TapLoaderStrategyTest.php index ef98f71..58eb9cf 100644 --- a/tests/Unit/Strategies/TapLoaderStrategyTest.php +++ b/tests/Unit/Strategies/TapLoaderStrategyTest.php @@ -2,7 +2,6 @@ namespace YorCreative\Scrubber\Test\Unit\Strategies; -use Illuminate\Support\Facades\Config; use YorCreative\Scrubber\Strategies\TapLoader\TapLoaderStrategy; use YorCreative\Scrubber\Tests\TestCase; @@ -18,7 +17,7 @@ public function it_can_load_wildcard_channels_and_tap() { $config = app()->make('config'); - Config::set('scrubber.tap_channels', ['*']); + $config->set('scrubber.tap_channels', ['*']); app(TapLoaderStrategy::class)->load($config); @@ -37,11 +36,12 @@ public function it_can_load_specific_channel_and_tap() { $config = app()->make('config'); - Config::set('scrubber.tap_channels', ['single']); + $config->set('scrubber.tap_channels', ['single']); app(TapLoaderStrategy::class)->load($config); $this->assertArrayHasKey('tap', $config->get('logging.channels.single')); + $this->assertArrayNotHasKey('tap', $config->get('logging.channels.papertrail')); } /** @@ -54,7 +54,7 @@ public function it_can_load_multiple_channels_and_tap() { $config = app()->make('config'); - Config::set('scrubber.tap_channels', ['single', 'papertrail']); + $config->set('scrubber.tap_channels', ['single', 'papertrail']); app(TapLoaderStrategy::class)->load($config); @@ -68,16 +68,35 @@ public function it_can_load_multiple_channels_and_tap() * @group Strategy * @group Unit */ - public function it_can_default_to_load_wildcard_channels_and_tap() + public function it_can_disable_tap() { $config = app()->make('config'); - Config::set('scrubber.tap_channels', null); + $config->set('scrubber.tap_channels', false); app(TapLoaderStrategy::class)->load($config); foreach ($config->get('logging.channels') as $channel) { - $this->assertArrayHasKey('tap', $channel); + $this->assertArrayNotHasKey('tap', $channel); + } + } + + /** + * @test + * + * @group Strategy + * @group Unit + */ + public function it_can_wont_tap_with_invalid_input_when_not_disabled() + { + $config = app()->make('config'); + + $config->set('scrubber.tap_channels', 1); + + app(TapLoaderStrategy::class)->load($config); + + foreach ($config->get('logging.channels') as $channel) { + $this->assertArrayNotHasKey('tap', $channel); } } }