Skip to content

Commit

Permalink
Merge pull request #162 from crf-devs/dont_log_health
Browse files Browse the repository at this point in the history
Avoid logging healthchecks
  • Loading branch information
mRoca authored Mar 27, 2020
2 parents f12e908 + a23145b commit 0a2f68b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions public/ping.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

die('pong');
12 changes: 10 additions & 2 deletions src/EventListener/RequestLoggerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public static function getSubscribedEvents(): array
public function onRequest(RequestEvent $event): void
{
$request = $event->getRequest();
if (self::isHealthCheck($request)) {
return;
}

$this->logger->info(
'Handle request',
Expand All @@ -51,15 +54,20 @@ public function onRequest(RequestEvent $event): void
);
}

public function logUser(): void
public function logUser(RequestEvent $event): void
{
if (null === $this->tokenStorage->getToken()) {
if (null === $this->tokenStorage->getToken() || self::isHealthCheck($event->getRequest())) {
return;
}

$this->logger->info('User logged in', ['username' => (string) $this->tokenStorage->getToken()->getUser()]);
}

private static function isHealthCheck(Request $request): bool
{
return false !== strpos((string) $request->headers->get('user-agent'), 'ELB-HealthChecker');
}

private static function getCleanHeaders(Request $request): array
{
$headers = $request->headers->all();
Expand Down

0 comments on commit 0a2f68b

Please sign in to comment.