Skip to content

Commit

Permalink
Fix issue with MonologCollector collector for Laravel >= v5.6 (#982)
Browse files Browse the repository at this point in the history
Logging was refactored in Laravel 5.6. `getMonolog()` method does not exist on a new Illuminate\Log\Logger
  • Loading branch information
ekateiva authored Aug 16, 2020
1 parent 1112fc1 commit 9ed8404
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/LaravelDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function ($level, $message = null, $context = null) use ($logger) {
}
);
} else {
$this->addCollector(new MonologCollector($this->app['log']->getMonolog()));
$this->addCollector(new MonologCollector($this->getMonologLogger()));
}
} catch (\Exception $e) {
$this->addThrowable(
Expand Down Expand Up @@ -1119,4 +1119,24 @@ protected function addServerTimingHeaders(Response $response)
$response->headers->set('Server-Timing', $headers, false);
}
}

/**
* @return \Monolog\Logger
* @throws Exception
*/
private function getMonologLogger()
{
// The logging was refactored in Laravel 5.6
if ($this->checkVersion('5.6')) {
$logger = $this->app['log']->getLogger();
} else {
$logger = $this->app['log']->getMonolog();
}

if (get_class($logger) !== 'Monolog\Logger') {
throw new Exception('Logger is not a Monolog\Logger instance');
}

return $logger;
}
}

0 comments on commit 9ed8404

Please sign in to comment.