feat: integrate Monolog for enhanced logging across providers and controller
This commit is contained in:
@@ -39,18 +39,24 @@ class GraphController
|
||||
public function graph(Request $request): Response
|
||||
{
|
||||
if ($this->allowedHosts !== [] && !in_array($request->getHost(), $this->allowedHosts, true)) {
|
||||
$this->logger->warning('GraphController: rejected request from disallowed host', ['host' => $request->getHost()]);
|
||||
|
||||
return new Response('Forbidden', 403);
|
||||
}
|
||||
|
||||
$theme = $request->query->get('theme', 'dark');
|
||||
$cacheKey = 'graph_' . $theme;
|
||||
|
||||
$svg = $this->cache->get($cacheKey, function (ItemInterface $item) use ($theme): string {
|
||||
$cacheMiss = false;
|
||||
$svg = $this->cache->get($cacheKey, function (ItemInterface $item) use ($theme, &$cacheMiss): string {
|
||||
$cacheMiss = true;
|
||||
$item->expiresAfter(3600);
|
||||
|
||||
return $this->renderer->render($this->fetchAllContributions(), $theme);
|
||||
});
|
||||
|
||||
$this->logger->debug('GraphController: cache ' . ($cacheMiss ? 'miss' : 'hit'), ['theme' => $theme]);
|
||||
|
||||
return new Response($svg, 200, [
|
||||
'Content-Type' => 'image/svg+xml',
|
||||
'Cache-Control' => 'public, max-age=3600',
|
||||
@@ -86,7 +92,7 @@ class GraphController
|
||||
try {
|
||||
$contributions = $this->merge($contributions, $provider->fetch());
|
||||
} catch (\Throwable $e) {
|
||||
$this->logger->warning(sprintf('%s fetch failed: %s', $provider::class, $e->getMessage()));
|
||||
$this->logger->warning(sprintf('%s fetch failed: %s', $provider::class, $e->getMessage()), ['exception' => $e]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user