Skip to content

Commit cc40474

Browse files
committed
refactor(config): Remove RequestServerCollector and update config
- Removed the RequestServerCollector from the configuration to simplify the collectors used. - Updated the channels configuration to use environment variables for the log channel and mailer settings. - Added a flush method to the Channel class to reset skipped callbacks.
1 parent 821edd9 commit cc40474

File tree

9 files changed

+17
-39
lines changed

9 files changed

+17
-39
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ php artisan vendor:publish --provider="Guanguans\\LaravelExceptionNotify\\Except
5151
### Configure channels in the `config/exception-notify.php` and `.env` file
5252

5353
```dotenv
54-
# EXCEPTION_NOTIFY_DEFAULTS=dingTalk,lark,mail,slack,telegram,...
55-
EXCEPTION_NOTIFY_DEFAULTS=log,slack,weWork
54+
# EXCEPTION_NOTIFY_STACK_CHANNELS=dingTalk,lark,mail,slack,telegram,...
55+
EXCEPTION_NOTIFY_STACK_CHANNELS=log,slack,weWork
5656
EXCEPTION_NOTIFY_SLACK_WEBHOOK=https://hooks.slack.com/services/TPU9A9/B038KNUC0GY/6pKH3vfa3mjlUPcgLSjzR
5757
EXCEPTION_NOTIFY_WEWORK_TOKEN=73a3d5a3-ceff-4da8-bcf3-ff5891778
5858
```

config/exception-notify.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use Guanguans\LaravelExceptionNotify\Collectors\RequestPostCollector;
2424
use Guanguans\LaravelExceptionNotify\Collectors\RequestQueryCollector;
2525
use Guanguans\LaravelExceptionNotify\Collectors\RequestRawFileCollector;
26-
use Guanguans\LaravelExceptionNotify\Collectors\RequestServerCollector;
2726
use Guanguans\LaravelExceptionNotify\Contracts\TemplateContract;
2827
use Guanguans\LaravelExceptionNotify\Jobs\ReportExceptionJob;
2928
use Guanguans\LaravelExceptionNotify\Mail\ReportExceptionMail;
@@ -90,7 +89,6 @@
9089
// RequestPostCollector::class,
9190
// RequestFileCollector::class,
9291
// RequestRawFileCollector::class,
93-
// RequestServerCollector::class,
9492
],
9593

9694
/**
@@ -136,15 +134,15 @@
136134
*/
137135
'log' => [
138136
'driver' => 'log',
139-
'channel' => null,
137+
'channel' => env('EXCEPTION_NOTIFY_LOG_CHANNEL'),
140138
],
141139

142140
/**
143141
* @see \Guanguans\LaravelExceptionNotify\Channels\MailChannel
144142
*/
145143
'mail' => [
146144
'driver' => 'mail',
147-
'mailer' => null,
145+
'mailer' => env('EXCEPTION_NOTIFY_MAIL_MAILER'),
148146
'class' => ReportExceptionMail::class,
149147
'title' => TemplateContract::TITLE,
150148
'content' => TemplateContract::CONTENT,

src/Channels/Channel.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public static function skipWhen(\Closure $callback): void
7575
self::$skipCallbacks[] = $callback;
7676
}
7777

78+
public static function flush(): void
79+
{
80+
self::$skipCallbacks = [];
81+
}
82+
7883
public function shouldReport(\Throwable $throwable): bool
7984
{
8085
return !$this->shouldntReport($throwable);

src/Collectors/RequestServerCollector.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Facades/ExceptionNotify.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* @method static void reporting(mixed $listener)
4242
* @method static void reported(mixed $listener)
4343
* @method static void skipWhen(\Closure $callback)
44+
* @method static void flush()
4445
* @method static bool shouldReport(\Throwable $throwable)
4546
*
4647
* @see \Guanguans\LaravelExceptionNotify\ExceptionNotifyManager

src/Support/helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function json_pretty_encode(mixed $value, int $options = 0, int $depth = 512): s
104104
{
105105
return json_encode(
106106
$value,
107-
\JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES | \JSON_THROW_ON_ERROR | $options,
107+
\JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES | \JSON_THROW_ON_ERROR | \JSON_FORCE_OBJECT | $options,
108108
$depth
109109
);
110110
}

tests/Channels/ChannelTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525

2626
it('can listen reporting and reported event', function (): void {
2727
ExceptionNotify::reporting(function (ReportingEvent $reportingEvent): void {
28-
Log::info($reportingEvent::class);
28+
// Log::info($reportingEvent::class);
2929
});
3030

3131
ExceptionNotify::reported(function (ReportedEvent $reportedEvent): void {
32-
Log::info($reportedEvent::class);
32+
// Log::info($reportedEvent::class);
3333
});
3434

3535
expect($this->app->make(ExceptionNotifyManager::class))

tests/Pest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
* @see https://github.com/guanguans/laravel-exception-notify
1818
*/
1919

20-
use Guanguans\LaravelExceptionNotify\Facades\ExceptionNotify;
20+
use Guanguans\LaravelExceptionNotify\Channels\Channel;
2121
use Guanguans\LaravelExceptionNotifyTests\TestCase;
2222
use Illuminate\Support\Collection;
23+
use Illuminate\Support\Facades\File;
2324

2425
uses(TestCase::class)
2526
->beforeAll(function (): void {})
2627
->beforeEach(function (): void {
27-
(fn (): array => self::$skipCallbacks = [])->call(ExceptionNotify::driver());
28+
Channel::flush();
29+
File::delete(glob(storage_path('logs/*.log')));
2830
})
2931
->afterEach(function (): void {})
3032
->afterAll(function (): void {})

tests/TestCase.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use Guanguans\LaravelExceptionNotify\Collectors\RequestPostCollector;
2828
use Guanguans\LaravelExceptionNotify\Collectors\RequestQueryCollector;
2929
use Guanguans\LaravelExceptionNotify\Collectors\RequestRawFileCollector;
30-
use Guanguans\LaravelExceptionNotify\Collectors\RequestServerCollector;
3130
use Guanguans\LaravelExceptionNotify\ExceptionNotifyServiceProvider;
3231
use Guanguans\LaravelExceptionNotify\Exceptions\RuntimeException;
3332
use Guanguans\LaravelExceptionNotify\Facades\ExceptionNotify;
@@ -92,7 +91,6 @@ protected function defineEnvironment($app): void
9291
RequestPostCollector::class,
9392
RequestQueryCollector::class,
9493
RequestRawFileCollector::class,
95-
RequestServerCollector::class,
9694
]);
9795
config()->set('exception-notify.channels.log.pipes', [
9896
AddKeywordChorePipe::with('keyword'),

0 commit comments

Comments
 (0)