Skip to content

Commit 64ed95d

Browse files
author
ityaozm@gmail.com
committed
perf(AppServiceProvider): extend logger to use NullLogger
- Extend the LoggerInterface to return a NullLogger if the existing logger is not a NullLogger. - This change improves logging behavior by ensuring a consistent logger is used. - Enhances the application's ability to handle logging without errors.
1 parent a1cd4d8 commit 64ed95d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

app/Providers/AppServiceProvider.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Illuminate\Support\ServiceProvider;
2222
use Illuminate\Support\Str;
2323
use Illuminate\Support\Stringable;
24+
use Psr\Log\LoggerInterface;
25+
use Psr\Log\NullLogger;
2426
use Symfony\Component\Console\Input\ArgvInput;
2527
use Symfony\Component\Console\Output\ConsoleOutput;
2628

@@ -51,12 +53,19 @@ public function register(): void
5153
Str::mixin($this->app->make(StrMacro::class));
5254
}
5355

56+
/**
57+
* @throws \JsonException
58+
*/
5459
public function boot(): void
5560
{
5661
/** @see \Symfony\Component\VarDumper\VarDumper */
5762
/** @noinspection GlobalVariableUsageInspection */
5863
$_SERVER['VAR_DUMPER_FORMAT'] = 'server';
5964

65+
$this->app->extend(LoggerInterface::class, static function (LoggerInterface $logger): NullLogger {
66+
return $logger instanceof NullLogger ? $logger : new NullLogger();
67+
});
68+
6069
ConfigManager::load();
6170
}
6271
}

0 commit comments

Comments
 (0)