Skip to content

Commit

Permalink
Allow changing the configuration at runtime
Browse files Browse the repository at this point in the history
This makes the test pass that sets the log channel at runtime
  • Loading branch information
adriaanzon committed Mar 18, 2022
1 parent a75ff22 commit b782eb5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/ReportFailedJobListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ReportFailedJobListener
{
public function handle(JobFailed $event): void
{
if (! config('telescope.enabled')) {
if (! config('telescope.enabled') || ! config('telescope-monitor.report_failed_jobs')) {
return;
}

Expand Down
9 changes: 9 additions & 0 deletions src/TelescopeExceptionLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ public function log(array $entries, ?string $channel = null): void
}
}
}

public function logToConfiguredChannel(array $entries): void
{
if (blank($channel = config('telescope-monitor.log_channel'))) {
return;
}

$this->log($entries, $channel);
}
}
12 changes: 4 additions & 8 deletions src/TelescopeMonitorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ public function register()

$this->mergeConfigFrom(__DIR__ . '/../config/telescope-monitor.php', 'telescope-monitor');

if (filled($channel = config('telescope-monitor.log_channel'))) {
Telescope::afterStoring(
fn($entries) => $this->app->make(TelescopeExceptionLogger::class)->log($entries, $channel)
);
}
Telescope::afterStoring(
fn($entries) => $this->app->make(TelescopeExceptionLogger::class)->logToConfiguredChannel($entries)
);
}

public function boot()
{
if (config('telescope-monitor.report_failed_jobs')) {
Event::listen(JobFailed::class, ReportFailedJobListener::class);
}
Event::listen(JobFailed::class, ReportFailedJobListener::class);
}
}
2 changes: 1 addition & 1 deletion tests/Integration/LogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LogTest extends TestCase
{
use RefreshDatabase;

protected function getEnvironmentSetUp($app)
protected function defineEnvironment($app)
{
$app['config']->set('telescope-monitor.log_channel', 'null');
}
Expand Down

0 comments on commit b782eb5

Please sign in to comment.