Skip to content

Commit

Permalink
Use Ignition for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Apr 29, 2024
1 parent 1cc2595 commit 4433159
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/Commands/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ReflectionProperty;
use Spatie\FlareClient\Flare;
use Spatie\FlareClient\Http\Exceptions\BadResponseCode;
use Spatie\Ignition\Ignition;

class TestCommand extends Command
{
Expand Down Expand Up @@ -114,11 +115,19 @@ protected function resolveConfigFlareLoggerFailures(): array

protected function isValidReportableCallbackFlareLogger(): bool
{
if ($this->hasReportableCallbackFlareLogger()) {
$configLoggerFailures = $this->resolveConfigFlareLoggerFailures();

$hasReportableCallbackFlareLogger = $this->hasReportableCallbackFlareLogger();

if(empty($configLoggerFailures) && $hasReportableCallbackFlareLogger) {
$this->info('❌ The Flare logger was defined in your Laravel `logging.php` config file and `bootstrap/app.php` file which can cause duplicate errors. Please remove the Flare logger from your `logging.php` config file.');
}

if ($hasReportableCallbackFlareLogger) {
return true;
}

if(empty($this->resolveConfigFlareLoggerFailures())) {
if(empty($configLoggerFailures)) {
return true;
}

Expand Down Expand Up @@ -160,7 +169,7 @@ protected function hasReportableCallbackFlareLogger(): bool
return false;
}

return $closureReturnTypeReflection->getName() === Flare::class;
return $closureReturnTypeReflection->getName() === Ignition::class;
}
} catch (ReflectionException $exception) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/InvalidConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public function getSolution(): Solution

return BaseSolution::create()
->setSolutionTitle('You provided an invalid log level')
->setSolutionDescription("Please change the log level in your `config/logging.php` file. Valid log levels are {$validLogLevelsString}.");
->setSolutionDescription("Please change the log level in your `config/logging.php` file or in `bootstrap/app.php`. Valid log levels are {$validLogLevelsString}.");
}
}
7 changes: 4 additions & 3 deletions src/Facades/Flare.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Support\Facades\Facade;
use Spatie\FlareClient\Flare as FlareClient;
use Spatie\Ignition\Ignition;
use Spatie\LaravelIgnition\Support\SentReports;
use Throwable;

Expand All @@ -24,10 +25,10 @@ protected static function getFacadeAccessor()

public static function handles(Exceptions $exceptions): void
{
$exceptions->reportable(static function (Throwable $exception): FlareClient {
$flare = app(FlareClient::class);
$exceptions->reportable(static function (Throwable $exception): Ignition {
$flare = app(Ignition::class);

$flare->report($exception);
$flare->handleException($exception);

return $flare;
});
Expand Down
1 change: 1 addition & 0 deletions src/Support/FlareLogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected function write(LogRecord $record): void
if (! $this->shouldReport($record->toArray())) {
return;
}

if ($this->hasException($record->toArray())) {
$report = $this->flare->report($record['context']['exception']);

Expand Down

0 comments on commit 4433159

Please sign in to comment.