Skip to content

Commit 2a3a3f5

Browse files
committed
TASK: Improve logging by showing the correct package key
1 parent 5a0d7d3 commit 2a3a3f5

4 files changed

Lines changed: 45 additions & 27 deletions

File tree

Classes/Flowpack/ElasticSearch/ContentRepositoryQueueIndexer/Command/NodeIndexQueueCommandController.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
namespace Flowpack\ElasticSearch\ContentRepositoryQueueIndexer\Command;
33

44
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexer;
5-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
65
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Mapping\NodeTypeMappingBuilder;
76
use Flowpack\ElasticSearch\ContentRepositoryQueueIndexer\Domain\Repository\NodeDataRepository;
87
use Flowpack\ElasticSearch\ContentRepositoryQueueIndexer\IndexingJob;
8+
use Flowpack\ElasticSearch\ContentRepositoryQueueIndexer\LoggerTrait;
99
use Flowpack\ElasticSearch\ContentRepositoryQueueIndexer\UpdateAliasJob;
1010
use Flowpack\JobQueue\Common\Job\JobManager;
1111
use TYPO3\Flow\Annotations as Flow;
@@ -20,6 +20,8 @@
2020
*/
2121
class NodeIndexQueueCommandController extends CommandController
2222
{
23+
use LoggerTrait;
24+
2325
/**
2426
* @Flow\Inject
2527
* @var JobManager
@@ -56,12 +58,6 @@ class NodeIndexQueueCommandController extends CommandController
5658
*/
5759
protected $nodeIndexer;
5860

59-
/**
60-
* @Flow\Inject
61-
* @var LoggerInterface
62-
*/
63-
protected $logger;
64-
6561
/**
6662
* Index all nodes by creating a new index and when everything was completed, switch the index alias.
6763
*
@@ -137,7 +133,7 @@ protected function createNextIndex($indexPostfix)
137133
{
138134
$this->nodeIndexer->setIndexNamePostfix($indexPostfix);
139135
$this->nodeIndexer->getIndex()->create();
140-
$this->logger->log(sprintf('action=indexing step=index-created index=%s', $this->nodeIndexer->getIndexName()), LOG_INFO);
136+
$this->log(sprintf('action=indexing step=index-created index=%s', $this->nodeIndexer->getIndexName()), LOG_INFO);
141137
}
142138

143139
/**
@@ -150,6 +146,6 @@ protected function updateMapping()
150146
/** @var \Flowpack\ElasticSearch\Domain\Model\Mapping $mapping */
151147
$mapping->apply();
152148
}
153-
$this->logger->log(sprintf('action=indexing step=mapping-updated index=%s', $this->nodeIndexer->getIndexName()), LOG_INFO);
149+
$this->log(sprintf('action=indexing step=mapping-updated index=%s', $this->nodeIndexer->getIndexName()), LOG_INFO);
154150
}
155151
}

Classes/Flowpack/ElasticSearch/ContentRepositoryQueueIndexer/IndexingJob.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Flowpack\JobQueue\Common\Queue\Message;
77
use Flowpack\JobQueue\Common\Queue\QueueInterface;
88
use TYPO3\Flow\Annotations as Flow;
9-
use TYPO3\Flow\Log\SystemLoggerInterface;
109
use TYPO3\Flow\Utility\Algorithms;
1110
use TYPO3\TYPO3CR\Domain\Factory\NodeFactory;
1211
use TYPO3\TYPO3CR\Domain\Model\NodeData;
@@ -19,6 +18,8 @@
1918
*/
2019
class IndexingJob implements JobInterface
2120
{
21+
use LoggerTrait;
22+
2223
/**
2324
* @var NodeIndexer
2425
* @Flow\Inject
@@ -43,12 +44,6 @@ class IndexingJob implements JobInterface
4344
*/
4445
protected $contextFactory;
4546

46-
/**
47-
* @var SystemLoggerInterface
48-
* @Flow\Inject
49-
*/
50-
protected $logger;
51-
5247
/**
5348
* @var string
5449
*/
@@ -108,20 +103,20 @@ public function execute(QueueInterface $queue, Message $message)
108103

109104
// Skip this iteration if the node can not be fetched from the current context
110105
if (!$currentNode instanceof NodeInterface) {
111-
$this->logger->log(sprintf('action=indexing step=failed node=%s message="Node could not be processed"', $node['nodeIdentifier']));
106+
$this->log(sprintf('action=indexing step=failed node=%s message="Node could not be processed"', $node['nodeIdentifier']));
112107
continue;
113108
}
114109

115110
$this->nodeIndexer->setIndexNamePostfix($this->indexPostfix);
116-
$this->logger->log(sprintf('action=indexing step=started node=%s', $currentNode->getIdentifier()));
111+
$this->log(sprintf('action=indexing step=started node=%s', $currentNode->getIdentifier()));
117112

118113
$this->nodeIndexer->indexNode($currentNode);
119114
}
120115

121116
$this->nodeIndexer->flush();
122117
$duration = microtime(true) - $startTime;
123118
$rate = $numberOfNodes / $duration;
124-
$this->logger->log(sprintf('action=indexing step=finished number_of_nodes=%d duration=%f nodes_per_second=%f', $numberOfNodes, $duration, $rate));
119+
$this->log(sprintf('action=indexing step=finished number_of_nodes=%d duration=%f nodes_per_second=%f', $numberOfNodes, $duration, $rate));
125120
});
126121

127122
return true;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
namespace Flowpack\ElasticSearch\ContentRepositoryQueueIndexer;
3+
4+
use TYPO3\Flow\Annotations as Flow;
5+
6+
/**
7+
* LoggerTrait
8+
*/
9+
trait LoggerTrait
10+
{
11+
/**
12+
* @var \TYPO3\Flow\Log\SystemLoggerInterface
13+
* @Flow\Inject
14+
*/
15+
protected $_logger;
16+
17+
/**
18+
* @param string $message The message to log
19+
* @param integer $severity An integer value, one of the LOG_* constants
20+
* @param mixed $additionalData A variable containing more information about the event to be logged
21+
* @param string $packageKey Key of the package triggering the log (determined automatically if not specified)
22+
* @param string $className Name of the class triggering the log (determined automatically if not specified)
23+
* @param string $methodName Name of the method triggering the log (determined automatically if not specified)
24+
* @return void
25+
* @api
26+
*/
27+
protected function log($message, $severity = LOG_INFO, $additionalData = null, $packageKey = null, $className = null, $methodName = null)
28+
{
29+
$packageKey = $packageKey ?: 'Flowpack.ElasticSearch.ContentRepositoryQueueIndexer';
30+
$this->_logger->log($message, $severity, $additionalData, $packageKey, $className, $methodName);
31+
}
32+
}

Classes/Flowpack/ElasticSearch/ContentRepositoryQueueIndexer/UpdateAliasJob.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
namespace Flowpack\ElasticSearch\ContentRepositoryQueueIndexer;
33

44
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexer;
5-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
65
use Flowpack\JobQueue\Common\Job\JobInterface;
76
use Flowpack\JobQueue\Common\Queue\Message;
87
use Flowpack\JobQueue\Common\Queue\QueueInterface;
@@ -14,18 +13,14 @@
1413
*/
1514
class UpdateAliasJob implements JobInterface
1615
{
16+
use LoggerTrait;
17+
1718
/**
1819
* @var NodeIndexer
1920
* @Flow\Inject
2021
*/
2122
protected $nodeIndexer;
2223

23-
/**
24-
* @var LoggerInterface
25-
* @Flow\Inject
26-
*/
27-
protected $logger;
28-
2924
/**
3025
* @var string
3126
*/
@@ -57,7 +52,7 @@ public function execute(QueueInterface $queue, Message $message)
5752
{
5853
$this->nodeIndexer->setIndexNamePostfix($this->indexPostfix);
5954
$this->nodeIndexer->updateIndexAlias();
60-
$this->logger->log(sprintf('action=indexing step=index-switched alias=%s', $this->indexPostfix), LOG_NOTICE);
55+
$this->log(sprintf('action=indexing step=index-switched alias=%s', $this->indexPostfix), LOG_NOTICE);
6156

6257
return true;
6358
}

0 commit comments

Comments
 (0)