Skip to content

Commit 2e65a33

Browse files
committed
TASK: Add log environment data to all logger calls
1 parent 926b40a commit 2e65a33

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

Classes/Driver/Version5/IndexerDriver.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Flowpack\ElasticSearch\Domain\Model\Document as ElasticSearchDocument;
2020
use Neos\ContentRepository\Domain\Model\NodeInterface;
2121
use Neos\Flow\Annotations as Flow;
22+
use Neos\Flow\Log\Utility\LogEnvironment;
2223

2324
/**
2425
* Indexer driver for Elasticsearch version 5.x
@@ -96,12 +97,12 @@ public function fulltext(NodeInterface $node, array $fulltextIndexOfNode, string
9697

9798
if ($closestFulltextNode->isRemoved()) {
9899
// fulltext root is removed, abort silently...
99-
$this->logger->debug(sprintf('NodeIndexer (%s): Fulltext root found for %s (%s) not updated, it is removed', $closestFulltextNodeDocumentIdentifier, $node->getPath(), $node->getIdentifier()));
100+
$this->logger->debug(sprintf('NodeIndexer (%s): Fulltext root found for %s (%s) not updated, it is removed', $closestFulltextNodeDocumentIdentifier, $node->getPath(), $node->getIdentifier()), LogEnvironment::fromMethodName(__METHOD__));
100101

101102
return [];
102103
}
103104

104-
$this->logger->debug(sprintf('NodeIndexer (%s): Updated fulltext index for %s (%s)', $closestFulltextNodeDocumentIdentifier, $closestFulltextNodeContextPath, $closestFulltextNode->getIdentifier()));
105+
$this->logger->debug(sprintf('NodeIndexer (%s): Updated fulltext index for %s (%s)', $closestFulltextNodeDocumentIdentifier, $closestFulltextNodeContextPath, $closestFulltextNode->getIdentifier()), LogEnvironment::fromMethodName(__METHOD__));
105106

106107
$upsertFulltextParts = [];
107108
if (!empty($fulltextIndexOfNode)) {

Classes/Eel/ElasticSearchQueryBuilder.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
declare(strict_types=1);
43

54
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel;
@@ -19,6 +18,7 @@
1918
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient;
2019
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception;
2120
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\QueryBuildingException;
21+
use Neos\Flow\Log\ThrowableStorageInterface;
2222
use Neos\Flow\Log\Utility\LogEnvironment;
2323
use Psr\Log\LoggerInterface;
2424
use Flowpack\ElasticSearch\Transfer\Exception\ApiException;
@@ -60,6 +60,12 @@ class ElasticSearchQueryBuilder implements QueryBuilderInterface, ProtectedConte
6060
*/
6161
protected $logger;
6262

63+
/**
64+
* @Flow\Inject
65+
* @var ThrowableStorageInterface
66+
*/
67+
protected $throwableStorage;
68+
6369
/**
6470
* @var boolean
6571
*/
@@ -190,6 +196,7 @@ public function sort($configuration): ElasticSearchQueryBuilder
190196
*
191197
* @param integer $limit
192198
* @return ElasticSearchQueryBuilder
199+
* @throws \Neos\Flow\Persistence\Exception\IllegalObjectTypeException
193200
* @api
194201
*/
195202
public function limit($limit)
@@ -571,7 +578,9 @@ public function getFullElasticSearchHitForNode(NodeInterface $node): array
571578
* This method is rather internal; just to be called from the ElasticSearchQueryResult. For the public API, please use execute()
572579
*
573580
* @return array<\Neos\ContentRepository\Domain\Model\NodeInterface>
581+
* @throws Exception
574582
* @throws \Flowpack\ElasticSearch\Exception
583+
* @throws \Neos\Flow\Http\Exception
575584
*/
576585
public function fetch(): array
577586
{
@@ -587,13 +596,13 @@ public function fetch(): array
587596

588597
$this->result['nodes'] = [];
589598

590-
$this->logThisQuery && $this->logger->debug(sprintf('Query Log (%s): %s -- execution time: %s ms -- Limit: %s -- Number of results returned: %s -- Total Results: %s', $this->logMessage, $request, (($timeAfterwards - $timeBefore) * 1000), $this->limit, count($searchResult->getHits()), $searchResult->getTotal()));
599+
$this->logThisQuery && $this->logger->debug(sprintf('Query Log (%s): %s -- execution time: %s ms -- Limit: %s -- Number of results returned: %s -- Total Results: %s', $this->logMessage, $request, (($timeAfterwards - $timeBefore) * 1000), $this->limit, count($searchResult->getHits()), $searchResult->getTotal()), LogEnvironment::fromMethodName(__METHOD__));
591600

592601
if (count($searchResult->getHits()) > 0) {
593602
$this->result['nodes'] = $this->convertHitsToNodes($searchResult->getHits());
594603
}
595604
} catch (ApiException $exception) {
596-
$this->logger->logException($exception);
605+
$this->throwableStorage->logThrowable($exception);
597606
$this->result['nodes'] = [];
598607
}
599608

@@ -640,7 +649,9 @@ public function executeUncached(): ElasticSearchQueryResult
640649
* Return the total number of hits for the query.
641650
*
642651
* @return integer
652+
* @throws Exception
643653
* @throws \Flowpack\ElasticSearch\Exception
654+
* @throws \Neos\Flow\Http\Exception
644655
* @api
645656
*/
646657
public function count()
@@ -654,7 +665,7 @@ public function count()
654665
$treatedContent = $response->getTreatedContent();
655666
$count = $treatedContent['count'];
656667

657-
$this->logThisQuery && $this->logger->debug('Count Query Log (' . $this->logMessage . '): ' . $request . ' -- execution time: ' . (($timeAfterwards - $timeBefore) * 1000) . ' ms -- Total Results: ' . $count);
668+
$this->logThisQuery && $this->logger->debug('Count Query Log (' . $this->logMessage . '): ' . $request . ' -- execution time: ' . (($timeAfterwards - $timeBefore) * 1000) . ' ms -- Total Results: ' . $count, LogEnvironment::fromMethodName(__METHOD__));
658669

659670
return $count;
660671
}
@@ -866,8 +877,10 @@ protected function convertHitsToNodes(array $hits): array
866877
* hiddenBeforeDateTime or hiddenAfterDateTime properties of all nodes in the result.
867878
*
868879
* @return int
880+
* @throws Exception
869881
* @throws QueryBuildingException
870882
* @throws \Flowpack\ElasticSearch\Exception
883+
* @throws \Neos\Flow\Http\Exception
871884
*/
872885
public function cacheLifetime(): int
873886
{
@@ -890,8 +903,10 @@ public function cacheLifetime(): int
890903
/**
891904
* @param string $dateField
892905
* @return int
906+
* @throws Exception
893907
* @throws QueryBuildingException
894908
* @throws \Flowpack\ElasticSearch\Exception
909+
* @throws \Neos\Flow\Http\Exception
895910
*/
896911
protected function getNearestFutureDate(string $dateField): int
897912
{

0 commit comments

Comments
 (0)