Skip to content

Commit cc41425

Browse files
committed
!!! TASK: Refactor and simplify logging for compatibility with FLow 6.0
- Change the Interface and logger calls - Remove the specified elasticsearch logger and logfile
1 parent 618da54 commit cc41425

13 files changed

Lines changed: 46 additions & 108 deletions

Classes/Command/NodeIndexCommandController.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\Error\ErrorInterface;
1919
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\NodeTypeMappingBuilderInterface;
2020
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexer;
21-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
2221
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\ErrorHandlingService;
2322
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\IndexWorkspaceTrait;
2423
use Flowpack\ElasticSearch\Domain\Model\Mapping;
@@ -33,9 +32,11 @@
3332
use Neos\Flow\Cli\CommandController;
3433
use Neos\Flow\Configuration\ConfigurationManager;
3534
use Neos\Flow\Configuration\Exception\InvalidConfigurationTypeException;
35+
use Neos\Flow\Log\Utility\LogEnvironment;
3636
use Neos\Flow\Mvc\Exception\StopActionException;
3737
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
3838
use Neos\Neos\Controller\CreateContentContextTrait;
39+
use Psr\Log\LoggerInterface;
3940
use Symfony\Component\Yaml\Yaml;
4041

4142
/**
@@ -246,18 +247,18 @@ public function indexNodeCommand(string $identifier, string $workspace = null):
246247
public function buildCommand(int $limit = null, bool $update = false, string $workspace = null, string $postfix = ''): void
247248
{
248249
if ($workspace !== null && $this->workspaceRepository->findByIdentifier($workspace) === null) {
249-
$this->logger->log('The given workspace (' . $workspace . ') does not exist.', LOG_ERR);
250+
$this->logger->error('The given workspace (' . $workspace . ') does not exist.', LogEnvironment::fromMethodName(__METHOD__));
250251
$this->quit(1);
251252
}
252253

253254
if ($update === true) {
254-
$this->logger->log('!!! Update Mode (Development) active!');
255+
$this->logger->warning('!!! Update Mode (Development) active!', LogEnvironment::fromMethodName(__METHOD__));
255256
} else {
256257
$this->createNewIndex($postfix);
257258
}
258259
$this->applyMapping();
259260

260-
$this->logger->log(sprintf('Indexing %snodes ... ', ($limit !== null ? 'the first ' . $limit . ' ' : '')));
261+
$this->logger->info(sprintf('Indexing %snodes ... ', ($limit !== null ? 'the first ' . $limit . ' ' : '')), LogEnvironment::fromMethodName(__METHOD__));
261262

262263
$count = 0;
263264

@@ -291,7 +292,7 @@ public function buildCommand(int $limit = null, bool $update = false, string $wo
291292
$this->outputLine();
292293
$this->outputLine('<error>Check your logs for more information</error>');
293294
} else {
294-
$this->logger->log('Done. (indexed ' . $count . ' nodes)', LOG_INFO);
295+
$this->logger->info('Done. (indexed ' . $count . ' nodes)', LogEnvironment::fromMethodName(__METHOD__));
295296
}
296297
$this->nodeIndexer->getIndex()->refresh();
297298

@@ -313,17 +314,17 @@ public function cleanupCommand(): void
313314
$indicesToBeRemoved = $this->nodeIndexer->removeOldIndices();
314315
if (count($indicesToBeRemoved) > 0) {
315316
foreach ($indicesToBeRemoved as $indexToBeRemoved) {
316-
$this->logger->log('Removing old index ' . $indexToBeRemoved);
317+
$this->logger->info('Removing old index ' . $indexToBeRemoved, LogEnvironment::fromMethodName(__METHOD__));
317318
}
318319
} else {
319-
$this->logger->log('Nothing to remove.');
320+
$this->logger->info('Nothing to remove.', LogEnvironment::fromMethodName(__METHOD__));
320321
}
321322
} catch (ApiException $exception) {
322323
$response = json_decode($exception->getResponse());
323324
if ($response->error instanceof \stdClass) {
324-
$this->logger->log(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s: %s"', $response->status, $response->error->type, $response->error->reason));
325+
$this->logger->info(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s: %s"', $response->status, $response->error->type, $response->error->reason), LogEnvironment::fromMethodName(__METHOD__));
325326
} else {
326-
$this->logger->log(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s"', $response->status, $response->error));
327+
$this->logger->info(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s"', $response->status, $response->error), LogEnvironment::fromMethodName(__METHOD__));
327328
}
328329
}
329330
}
@@ -339,11 +340,11 @@ protected function createNewIndex(string $postfix): void
339340
{
340341
$this->nodeIndexer->setIndexNamePostfix($postfix ?: (string)time());
341342
if ($this->nodeIndexer->getIndex()->exists() === true) {
342-
$this->logger->log(sprintf('Deleted index with the same postfix (%s)!', $postfix), LOG_WARNING);
343+
$this->logger->warning(sprintf('Deleted index with the same postfix (%s)!', $postfix), LogEnvironment::fromMethodName(__METHOD__));
343344
$this->nodeIndexer->getIndex()->delete();
344345
}
345346
$this->nodeIndexer->getIndex()->create();
346-
$this->logger->log('Created index ' . $this->nodeIndexer->getIndexName());
347+
$this->logger->info('Created index ' . $this->nodeIndexer->getIndexName(), LogEnvironment::fromMethodName(__METHOD__));
347348
}
348349

349350
/**
@@ -359,6 +360,6 @@ protected function applyMapping(): void
359360
/** @var Mapping $mapping */
360361
$mapping->apply();
361362
}
362-
$this->logger->log('Updated Mapping.');
363+
$this->logger->info('Updated Mapping.', LogEnvironment::fromMethodName(__METHOD__));
363364
}
364365
}

Classes/Driver/AbstractDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient;
18-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
18+
use Psr\Log\LoggerInterface;
1919
use Neos\Flow\Annotations as Flow;
2020

2121
/**

Classes/Driver/AbstractIndexerDriver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use Neos\ContentRepository\Domain\Model\NodeInterface;
1818
use Neos\Flow\Annotations as Flow;
19+
use Neos\Flow\Log\Utility\LogEnvironment;
1920

2021
/**
2122
* Abstract Fulltext Indexer Driver
@@ -58,7 +59,7 @@ protected function findClosestFulltextRoot(NodeInterface $node)
5859
if ($closestFulltextNode === null) {
5960
// root of hierarchy, no fulltext root found anymore, abort silently...
6061
if ($node->getPath() !== '/' && $node->getPath() !== '/sites') {
61-
$this->logger->log(sprintf('NodeIndexer: No fulltext root found for node %s (%s)', $node->getIdentifier(), $node->getContextPath()), LOG_WARNING, null, 'ElasticSearch (CR)');
62+
$this->logger->warning(sprintf('NodeIndexer: No fulltext root found for node %s (%s)', $node->getIdentifier(), $node->getContextPath()), LogEnvironment::fromMethodName(__METHOD__));
6263
}
6364

6465
return null;

Classes/Driver/Version5/DocumentDriver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Neos\ContentRepository\Domain\Model\NodeInterface;
2222
use Neos\ContentRepository\Domain\Model\NodeType;
2323
use Neos\Flow\Annotations as Flow;
24+
use Neos\Flow\Log\Utility\LogEnvironment;
2425

2526
/**
2627
* Document driver for Elasticsearch version 5.x
@@ -90,7 +91,7 @@ public function deleteDuplicateDocumentNotMatchingType(Index $index, string $doc
9091
$result = $index->request('GET', '/_search/scroll?scroll=1m', [], $scrollId, false);
9192
$treatedContent = $result->getTreatedContent();
9293
}
93-
$this->logger->log(sprintf('NodeIndexer: Check duplicate nodes for %s (%s), found %d document(s)', $documentIdentifier, $nodeType->getName(), count($bulkRequest)), LOG_DEBUG, null, 'ElasticSearch (CR)');
94+
$this->logger->debug(sprintf('NodeIndexer: Check duplicate nodes for %s (%s), found %d document(s)', $documentIdentifier, $nodeType->getName(), count($bulkRequest)), LogEnvironment::fromMethodName(__METHOD__));
9495
if ($bulkRequest !== []) {
9596
$index->request('POST', '/_bulk', [], implode("\n", $bulkRequest) . "\n");
9697
}

Classes/Driver/Version5/IndexerDriver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ public function fulltext(NodeInterface $node, array $fulltextIndexOfNode, string
9696

9797
if ($closestFulltextNode->isRemoved()) {
9898
// fulltext root is removed, abort silently...
99-
$this->logger->log(sprintf('NodeIndexer (%s): Fulltext root found for %s (%s) not updated, it is removed', $closestFulltextNodeDocumentIdentifier, $node->getPath(), $node->getIdentifier()), LOG_DEBUG, null, 'ElasticSearch (CR)');
99+
$this->logger->debug(sprintf('NodeIndexer (%s): Fulltext root found for %s (%s) not updated, it is removed', $closestFulltextNodeDocumentIdentifier, $node->getPath(), $node->getIdentifier()));
100100

101101
return [];
102102
}
103103

104-
$this->logger->log(sprintf('NodeIndexer (%s): Updated fulltext index for %s (%s)', $closestFulltextNodeDocumentIdentifier, $closestFulltextNodeContextPath, $closestFulltextNode->getIdentifier()), LOG_DEBUG, null, 'ElasticSearch (CR)');
104+
$this->logger->debug(sprintf('NodeIndexer (%s): Updated fulltext index for %s (%s)', $closestFulltextNodeDocumentIdentifier, $closestFulltextNodeContextPath, $closestFulltextNode->getIdentifier()));
105105

106106
$upsertFulltextParts = [];
107107
if (!empty($fulltextIndexOfNode)) {

Classes/Eel/ElasticSearchQueryBuilder.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient;
2020
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception;
2121
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\QueryBuildingException;
22-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
22+
use Neos\Flow\Log\Utility\LogEnvironment;
23+
use Psr\Log\LoggerInterface;
2324
use Flowpack\ElasticSearch\Transfer\Exception\ApiException;
2425
use Neos\ContentRepository\Domain\Model\NodeInterface;
2526
use Neos\ContentRepository\Search\Search\QueryBuilderInterface;
@@ -586,7 +587,7 @@ public function fetch(): array
586587

587588
$this->result['nodes'] = [];
588589

589-
$this->logThisQuery && $this->logger->log(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()), LOG_DEBUG);
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()));
590591

591592
if (count($searchResult->getHits()) > 0) {
592593
$this->result['nodes'] = $this->convertHitsToNodes($searchResult->getHits());
@@ -653,7 +654,7 @@ public function count()
653654
$treatedContent = $response->getTreatedContent();
654655
$count = $treatedContent['count'];
655656

656-
$this->logThisQuery && $this->logger->log('Count Query Log (' . $this->logMessage . '): ' . $request . ' -- execution time: ' . (($timeAfterwards - $timeBefore) * 1000) . ' ms -- Total Results: ' . $count, LOG_DEBUG);
657+
$this->logThisQuery && $this->logger->debug('Count Query Log (' . $this->logMessage . '): ' . $request . ' -- execution time: ' . (($timeAfterwards - $timeBefore) * 1000) . ' ms -- Total Results: ' . $count);
657658

658659
return $count;
659660
}
@@ -712,7 +713,7 @@ public function moreLikeThis(array $like, array $fields = [], array $options = [
712713
$respondedDocuments = Arrays::getValueByPath($response, 'hits.hits');
713714

714715
if (count($respondedDocuments) === 0) {
715-
$this->logger->log(sprintf('The node with identifier %s was not found in the elasticsearch index.', $node->getIdentifier()), LOG_INFO);
716+
$this->logger->info(sprintf('The node with identifier %s was not found in the elasticsearch index.', $node->getIdentifier()), LogEnvironment::fromMethodName(__METHOD__));
716717
return [];
717718
}
718719

@@ -852,7 +853,7 @@ protected function convertHitsToNodes(array $hits): array
852853
}
853854
}
854855

855-
$this->logThisQuery && $this->logger->log('Returned nodes (' . $this->logMessage . '): ' . count($nodes), LOG_DEBUG);
856+
$this->logThisQuery && $this->logger->debug('Returned nodes (' . $this->logMessage . '): ' . count($nodes));
856857

857858
$this->elasticSearchHitsIndexedByNodeFromLastRequest = $elasticSearchHitPerNode;
858859

Classes/Factory/AbstractDriverSpecificObjectFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\DriverConfigurationException;
18-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
18+
use Psr\Log\LoggerInterface;
1919
use Neos\Flow\Annotations as Flow;
2020

2121
/**
@@ -57,7 +57,7 @@ protected function resolve(string $type)
5757

5858
$className = trim($this->mapping[$version][$type]['className']);
5959

60-
$this->logger->log(sprintf('Load %s implementation for Elastic %s (%s)', $type, $version, $className), LOG_DEBUG);
60+
$this->logger->debug(sprintf('Load %s implementation for Elastic %s (%s)', $type, $version, $className));
6161

6262
if (!isset($this->mapping[$version][$type]['arguments'])) {
6363
return new $className();

Classes/Indexer/Error/BulkIndexingError.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
* source code.
1515
*/
1616

17-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
17+
use Neos\Flow\Log\Utility\LogEnvironment;
18+
use Psr\Log\LoggerInterface;
1819
use Neos\Flow\Annotations as Flow;
1920

2021
/**
@@ -76,9 +77,9 @@ public function log(): void
7677
{
7778
if (file_exists(FLOW_PATH_DATA . 'Logs/Elasticsearch') && is_dir(FLOW_PATH_DATA . 'Logs/Elasticsearch') && is_writable(FLOW_PATH_DATA . 'Logs/Elasticsearch')) {
7879
file_put_contents($this->filename, $this->renderErrors());
79-
$this->logger->log($this->message, LOG_ERR, [], 'Flowpack.ElasticSearch.ContentRepositoryAdaptor', __CLASS__, __FUNCTION__);
80+
$this->logger->error($this->message, LogEnvironment::fromMethodName(__METHOD__));
8081
} else {
81-
$this->logger->log(sprintf('Could not write indexing errors backtrace into %s because the directory could not be created or is not writable.', FLOW_PATH_DATA . 'Logs/Elasticsearch/'), LOG_WARNING, [], 'Flowpack.ElasticSearch.ContentRepositoryAdaptor', __CLASS__, __FUNCTION__);
82+
$this->logger->warning(sprintf('Could not write indexing errors backtrace into %s because the directory could not be created or is not writable.', FLOW_PATH_DATA . 'Logs/Elasticsearch/'), LogEnvironment::fromMethodName(__METHOD__));
8283
}
8384
}
8485

Classes/Indexer/Error/MalformedBulkRequestError.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
* source code.
1515
*/
1616

17-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
17+
use Neos\Flow\Log\Utility\LogEnvironment;
18+
use Psr\Log\LoggerInterface;
1819
use Neos\Flow\Annotations as Flow;
1920

2021
/**
@@ -55,7 +56,7 @@ public function __construct($message, array $tuple)
5556
*/
5657
public function log(): void
5758
{
58-
$this->logger->log($this->message(), LOG_ERR, $this->tuple);
59+
$this->logger->error($this->message(), LogEnvironment::fromMethodName(__METHOD__) + $this->tuple);
5960
}
6061

6162
/**

0 commit comments

Comments
 (0)