Skip to content

Commit aa7b060

Browse files
Change log parameters for suggest search to include searchTerm and locale.
1 parent 684f1b7 commit aa7b060

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/Controller/SuggestLocationController.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
use Symfony\Component\HttpFoundation\Request;
1010
use Symfony\Component\HttpFoundation\Response;
1111
use Symfony\Component\Routing\Annotation\Route;
12+
use Symfony\Contracts\Translation\TranslatorInterface;
1213

1314
class SuggestLocationController extends AbstractController
1415
{
1516
private LoggerInterface $logger;
17+
private TranslatorInterface $translator;
1618

17-
public function __construct(LoggerInterface $logger)
19+
public function __construct(LoggerInterface $logger, TranslatorInterface $translator)
1820
{
1921
$this->logger = $logger;
22+
$this->translator = $translator;
2023
}
2124

2225
/**
@@ -27,7 +30,7 @@ public function suggestExactPlaces(Request $request, SuggestLocationModel $model
2730
$response = new JsonResponse();
2831
$searchTerm = $request->query->get('term', '');
2932

30-
$this->logger->alert("Search term: {$searchTerm}");
33+
$this->logSearchInfo(__METHOD__, $searchTerm);
3134

3235
$result = $model->getSuggestionsForPlacesExact($searchTerm);
3336
$response->setData($result);
@@ -43,7 +46,7 @@ public function suggestPlaces(Request $request, SuggestLocationModel $model): Js
4346
$response = new JsonResponse();
4447
$searchTerm = $request->query->get('term', '');
4548

46-
$this->logger->alert("Search term: {$searchTerm}");
49+
$this->logSearchInfo(__METHOD__, $searchTerm);
4750

4851
$result = $model->getSuggestionsForPlaces($searchTerm);
4952
$response->setData($result);
@@ -62,11 +65,16 @@ public function suggestLocations(Request $request, SuggestLocationModel $model):
6265
$response = new JsonResponse();
6366
$searchTerm = $request->query->get('term', '');
6467

65-
$this->logger->alert("Search term: {$searchTerm}");
68+
$this->logSearchInfo(__METHOD__, $searchTerm);
6669

6770
$result = $model->getSuggestionsForLocations($searchTerm);
6871
$response->setData($result);
6972

7073
return $response;
7174
}
75+
76+
private function logSearchInfo(string $function, string $searchTerm)
77+
{
78+
$this->logger->alert($function, ['locale' => $this->translator->getLocale(), 'searchTerm' => $searchTerm]);
79+
}
7280
}

0 commit comments

Comments
 (0)