Skip to content

Commit

Permalink
Log non404 4xx repsonses
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Nov 6, 2024
1 parent e23c914 commit 9332684
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"classmap": ["src/"]
},
"autoload-dev": {
"psr-4": {
Expand Down
10 changes: 10 additions & 0 deletions src/EventListener/RequestStatsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
use Monolog\Logger;
use Monolog\LogRecord;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;

class RequestStatsListener
{
Expand Down Expand Up @@ -69,4 +71,12 @@ public function onResponse(ResponseEvent $e): void
};
$this->statsd->increment('app.status.'.$statsdCode, 1, 1, ['route' => $e->getRequest()->attributes->get('_route')]);
}

#[AsEventListener()]
public function onException(ExceptionEvent $e): void
{
if ($e->getThrowable() instanceof BadRequestHttpException && $e->getThrowable()->getCode() !== 404) {
$this->logger->error('Bad request', ['exception' => $e->getThrowable()]);
}
}
}

0 comments on commit 9332684

Please sign in to comment.