Skip to content

Commit

Permalink
[11.x] Fix 'pushProcessor method not found on LoggerInterface' error …
Browse files Browse the repository at this point in the history
…(#52117)

* add Logger@pushProcessor()

* revert IDE style

* add check to LogManager instead

* move to closure

* remove unused import

* add test

* readability

* style
  • Loading branch information
cosmastech authored Jul 16, 2024
1 parent fa6ce74 commit 5832371
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions LogManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,13 @@ protected function get($name, ?array $config = null)
{
try {
return $this->channels[$name] ?? with($this->resolve($name, $config), function ($logger) use ($name) {
return $this->channels[$name] = tap($this->tap($name, new Logger($logger, $this->app['events']))
->withContext($this->sharedContext))
->pushProcessor(function ($record) {
$loggerWithContext = $this->tap(
$name,
new Logger($logger, $this->app['events'])
)->withContext($this->sharedContext);

if (method_exists($loggerWithContext->getLogger(), 'pushProcessor')) {
$loggerWithContext->pushProcessor(function ($record) {
if (! $this->app->bound(ContextRepository::class)) {
return $record;
}
Expand All @@ -148,6 +152,9 @@ protected function get($name, ?array $config = null)
...$this->app[ContextRepository::class]->all(),
]);
});
}

return $this->channels[$name] = $loggerWithContext;
});
} catch (Throwable $e) {
return tap($this->createEmergencyLogger(), function ($logger) use ($e) {
Expand Down

0 comments on commit 5832371

Please sign in to comment.